Skip to content

Instantly share code, notes, and snippets.

@alanleard
Created October 10, 2011 20:49
Show Gist options
  • Save alanleard/1276487 to your computer and use it in GitHub Desktop.
Save alanleard/1276487 to your computer and use it in GitHub Desktop.
Move and Drop Mapview
var win1 = Titanium.UI.createWindow();
var mapView = Ti.Map.createView({
mapType: Ti.Map.STANDARD_TYPE,
region:{
latitude:33.74511, longitude:-84.38993,
latitudeDelta:0.5, longitudeDelta:0.5
},
animate:true,
regionFit:true,
userLocation:true
});
var count = 1
var annotation = Titanium.Map.createAnnotation({
title:"Dropped Annotation",
animate:true
});
var box = Ti.UI.createView({
width:20,
height:20,
borderColor:'red',
borderWidth:3,
touchEnabled:false
});
mapView.addEventListener('regionChanged', function(e) {
count++;
//if(count == 4){
mapView.removeAnnotation(annotation);
var latitude = e.latitude;
var longitude = e.longitude;
var latitudeDelta = e.latitudeDelta;
var longitudeDelta = e.longitudeDelta;
Ti.API.info(count+" latitude: " + latitude + " longitude: " + longitude + " latitudeDelta: " + latitudeDelta + " longitudeDelta: " + longitudeDelta);
annotation.latitude = latitude;
annotation.longitude = longitude;
annotation.subtitle = 'Determing Address...'
mapView.addAnnotation(annotation);
// annotation.addEventListener('click', function(){
Titanium.Geolocation.reverseGeocoder(latitude,longitude,function(evt)
{
if (evt.success) {
var places = evt.places;
if (places && places.length) {
annotation.title=places[0].city;
annotation.subtitle =places[0].address;
} else {
annotation.subtitle = "No address found";
}
Ti.API.debug("reverse geolocation result = "+JSON.stringify(evt));
}
else {
Ti.UI.createAlertDialog({
title:'Reverse geo error',
message:evt.error
}).show();
Ti.API.info("Code translation: "+translateErrorCode(e.code));
}
});
//count = 1;
//}
});
win1.add(mapView);
win1.add(box);
win1.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment