Skip to content

Instantly share code, notes, and snippets.

@exclusiveTanim
Last active August 29, 2015 13:58
Show Gist options
  • Save exclusiveTanim/9993253 to your computer and use it in GitHub Desktop.
Save exclusiveTanim/9993253 to your computer and use it in GitHub Desktop.
Code for Geolocation and Mapping
/*Its a simple code for Map*/
var MapModule = require('ti.map');
var win = Ti.UI.createWindow({backgroundColor: 'white'});
var scrollView = Ti.UI.createScrollView({
top : 20,
layout : 'vertical',
contentWidth : 'auto',
contentHeight : 'auto',
showVerticalScrollIndicator : true,
height : '75%',
});
win.add(scrollView);
var map1 = MapModule.createView({
userLocation: true,
mapType: MapModule.NORMAL_TYPE,
animate: true,
region: {latitude: -33.87365, longitude: 151.20689, latitudeDelta: 0.1, longitudeDelta: 0.1 },
height: '50%',
top: 0,
left: 0,
width: '50%'
});
var map2 = MapModule.createView({
userLocation: true,
mapType: MapModule.TERRAIN_TYPE,
animate: true,
region: {latitude: -33.87365, longitude: 151.20689, latitudeDelta: 0.1, longitudeDelta: 0.1 },
height: '50%',
top: 0,
right: 0,
width: '50%'
});
var map3 = MapModule.createView({
userLocation: true,
mapType: MapModule.SATELLITE_TYPE,
animate: true,
region: {latitude: -33.87365, longitude: 151.20689, latitudeDelta: 0.1, longitudeDelta: 0.1 },
height: '50%',
bottom: 0,
left: 0,
width: '50%'
});
var map4 = MapModule.createView({
userLocation: true,
mapType: MapModule.HYBRID_TYPE,
animate: true,
region: {latitude: -33.87365, longitude: 151.20689, latitudeDelta: 0.1, longitudeDelta: 0.1 },
height: '100%',
bottom: 0,
right: 0,
width: '100%',
traffic: true
});
win.add(map1);
win.add(map2);
win.add(map3);
win.add(map4);
var longitude;
var latitude;
ssTitanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST;
Titanium.Geolocation.distanceFilter = 10;
Titanium.Geolocation.getCurrentPosition(function(e)
{
if (!e.success || e.error)
{
alert('error ' + JSON.stringify(e.error));
return;
}
longitude = e.coords.longitude;
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;
});
var locationCallback = function(e)
{
if (!e.success || 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;
setTimeout(function()
{
},100);
// reverse geo
Titanium.Geolocation.reverseGeocoder(latitude,longitude,function(evt)
{
if (evt.success) {
var places = evt.places;
if (places && places.length) {
//reverseGeo.text = places[0].address;
var place = places[0].address;
//alert("Current location "+place);
// Create a Label.
var data = Ti.UI.createLabel({
text : places[0].address,
color : '#000',
font : {fontSize: 15},
height : Ti.UI.SIZE,
width : Ti.UI.FILL,
textAlign : 'center'
});
// Add to the parent view.
scrollView.add(data);
} else {
//reverseGeo.text = "No address found";
alert("No address found");
}
//Ti.API.debug("reverse geolocation result = "+JSON.stringify(evt));
}
else {
}
});
};
Titanium.Geolocation.addEventListener('location', locationCallback);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment