Created
November 18, 2011 01:00
-
-
Save srahim/1375173 to your computer and use it in GitHub Desktop.
maptest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win1 = Titanium.UI.createWindow({ | |
title:'Map1', | |
navBarHidden:true | |
}); | |
function findZoomRegion(points) { | |
var tmpDeltatLat = 0, tmpDeltatLong = 0, maxDeltatLat = 0, maxDeltatLong = 0, centerLat = 0, centerLong = 0; | |
for(var i = 0; i <= Math.floor(points.length / 2); i++) { | |
for(var j = 3; j >= Math.floor(points.length / 2); j--) { | |
if(j != i) { | |
tmpDeltatLat = Math.abs(Math.abs(points[i].latitude) - Math.abs(points[j].latitude)); | |
if(tmpDeltatLat > maxDeltatLat) { | |
maxDeltatLat = tmpDeltatLat; | |
centerLat = Math.min(points[i].latitude, points[j].latitude) + maxDeltatLat / 2; | |
} | |
tmpDeltatLong = Math.abs(Math.abs(points[i].longitude) - Math.abs(points[j].longitude)); | |
if(tmpDeltatLong > maxDeltatLong) { | |
maxDeltatLong = tmpDeltatLong; | |
centerLong = Math.min(points[i].longitude, points[j].longitude) + maxDeltatLong / 2; | |
} | |
} | |
} | |
} | |
var region = { | |
latitude : centerLat, | |
longitude : centerLong, | |
latitudeDelta : maxDeltatLat/4, | |
longitudeDelta : maxDeltatLong/4 | |
}; | |
return region; | |
} | |
var Points = [{latitude:42.813121,longitude:-70.866047},{latitude:41.813121,longitude:-72.875304},{latitude:40.813121,longitude:-73.866047},{latitude:43.813121,longitude:-61.866047}]; | |
var point1 = Titanium.Map.createAnnotation({ | |
latitude:42.813121, | |
longitude:-70.866047, | |
title:"aaa", | |
subtitle:'aaA', | |
pincolor:Titanium.Map.ANNOTATION_RED, | |
animate:true, | |
leftButton: '../images/appcelerator_small.png', | |
myid:1 // CUSTOM ATTRIBUTE THAT IS PASSED INTO EVENT OBJECTS | |
}); | |
var point2 = Titanium.Map.createAnnotation({ | |
latitude:41.813121, | |
longitude:-72.875304, | |
title:"aaa", | |
subtitle:'aaA', | |
pincolor:Titanium.Map.ANNOTATION_RED, | |
animate:true, | |
leftButton: '../images/appcelerator_small.png', | |
myid:1 // CUSTOM ATTRIBUTE THAT IS PASSED INTO EVENT OBJECTS | |
}); | |
var point3 = Titanium.Map.createAnnotation({ | |
latitude:40.813121, | |
longitude:-73.866047, | |
title:"aaa", | |
subtitle:'aaA', | |
pincolor:Titanium.Map.ANNOTATION_RED, | |
animate:true, | |
leftButton: '../images/appcelerator_small.png', | |
myid:1 // CUSTOM ATTRIBUTE THAT IS PASSED INTO EVENT OBJECTS | |
}); | |
var point4 = Titanium.Map.createAnnotation({ | |
latitude:43.813121, | |
longitude:-61.866047, | |
title:"aaa", | |
subtitle:'aaA', | |
pincolor:Titanium.Map.ANNOTATION_RED, | |
animate:true, | |
leftButton: '../images/appcelerator_small.png', | |
myid:1 // CUSTOM ATTRIBUTE THAT IS PASSED INTO EVENT OBJECTS | |
}); | |
var mapview = Titanium.Map.createView({ | |
mapType: Titanium.Map.STANDARD_TYPE, | |
regionFit:true, | |
region:findZoomRegion(Points), | |
annotations:[point1,point2,point3,point4] | |
}); | |
win1.add(mapview); | |
win1.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment