Skip to content

Instantly share code, notes, and snippets.

@Barneybook
Created June 14, 2012 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Barneybook/2928592 to your computer and use it in GitHub Desktop.
Save Barneybook/2928592 to your computer and use it in GitHub Desktop.
Titanium
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
var defaultDelta = 0.01;
var win1 = Titanium.UI.createWindow({
title:'map',
backgroundColor:'#fff',
fullscreen: true,
exitOnClose: true
});
function translateErrorCode(code) {
if (code == null) {
return null;
}
switch (code) {
case Ti.Geolocation.ERROR_LOCATION_UNKNOWN:
return "Location unknown";
case Ti.Geolocation.ERROR_DENIED:
return "Access denied";
case Ti.Geolocation.ERROR_NETWORK:
return "Network error";
case Ti.Geolocation.ERROR_HEADING_FAILURE:
return "Failure to detect heading";
case Ti.Geolocation.ERROR_REGION_MONITORING_DENIED:
return "Region monitoring access denied";
case Ti.Geolocation.ERROR_REGION_MONITORING_FAILURE:
return "Region monitoring access failure";
case Ti.Geolocation.ERROR_REGION_MONITORING_DELAYED:
return "Region monitoring setup delayed";
}
}
Titanium.Geolocation.getCurrentPosition(function(e)
{
if (!e.success || e.error)
{
//currentLocation.text = 'error: ' + JSON.stringify(e.error);
Ti.API.info("error: "+JSON.stringify(e.error));
Ti.API.info("Code translation: "+translateErrorCode(e.code));
//alert('error ' + JSON.stringify(e.error));
return;
}
var longitude = e.coords.longitude;
var latitude = e.coords.latitude;
var altitude = e.coords.altitude;
var heading = e.coords.heading;
var accuracy = e.coords.accuracy;
var speed = e.coords.speed;
var timestamp = e.coords.timestamp;
var altitudeAccuracy = e.coords.altitudeAccuracy;
Ti.API.info('speed ' + speed);
currentLocation.text = 'long:' + longitude + ' lat: ' + latitude;
Titanium.API.info('geo - current location: ' + new Date(timestamp) + ' long ' + longitude + ' lat ' + latitude + ' accuracy ' + accuracy);
});
Ti.API.info("XXX");
var corLat = 25.042771;
var corLong = 121.530445;
//公司現在地圖坐標
var LocationView = Titanium.Map.createAnnotation({
latitude:corLat,
longitude:corLong,
//latitude:latitudeNow,
//longitude:longitudeNow,
title:"遠颺科技",
subtitle:'忠孝東路二段100號5F-6 TEL:(02)2321-5977',
pincolor:Titanium.Map.ANNOTATION_RED,
animate:true,
myid:1
});
var presetAnnotations = [LocationView];
var mapview = Titanium.Map.createView({
mapType:Titanium.Map.STANDARD_TYPE,
region:
{
latitude:25.042771,longitude:121.530445,
latitudeDelta:defaultDelta,longitudeDelta:defaultDelta
},
animate:true,
regionFit:true,
userLocation:true,
annotations:presetAnnotations,
height:180,
top:0
});
mapview.selectAnnotation(LocationView);
win1.add(mapview);
win1.open();
/**/
Titanium.Geolocation.forwardGeocoder(addr,function(evt)
{
Ti.API.info('in forward ');
forwardGeo.text = "lat:"+evt.latitude+", long:"+evt.longitude;
Titanium.Geolocation.reverseGeocoder(evt.latitude,evt.longitude,function(evt)
{
if (evt.success) {
var text = "";
for (var i = 0; i < evt.places.length; i++) {
text += "" + i + ") " + evt.places[i].address + "\n";
}
Ti.API.info('Reversed forward: '+text);
}
else {
Ti.UI.createAlertDialog({
title:'Forward geo error',
message:evt.error
}).show();
Ti.API.info("Code translation: "+translateErrorCode(e.code));
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment