Showing multiple markers on map : Titanium -
i making app in have show map in application. able show map , able add markers using annotation on mapview.
problem 1> not able show multiple markers on map.
so body can me how can add multiple markers on map.
thanks,
rakesh
here map class use. include map.js file in window , call map.init , pass in array of map annotations add, center lat/long, top , bottom positions of map, , optionally lat/long delta. if want dynamically add annotations after map has been created can call other functions in class so:
var path = ti.platform.name == 'android' ? ti.filesystem.resourcesdirectory : "../../"; var map = { top: 0, bottom: 0, latitude: 0, longitude: 0, latitudedelta: 0.1, longitudedelta: 0.1, display: "map", init: function (annotations, latitude, longitude, top, bottom, delta) { if (top) map.top = top; if (bottom) map.bottom = bottom; if (delta) { map.latitudedelta = delta; map.longitudedelta = delta; } map.createmap(annotations, latitude, longitude); map.createoptions(); map.getlocation(); }, createmap: function (annotations, latitude, longitude) { map.mapview = ti.map.createview({ maptype: ti.map.standard_type, animate: true, regionfit: false, userlocation: true, region: { latitude: latitude, longitude: longitude, latitudedelta: map.latitudedelta, longitudedelta: map.longitudedelta }, annotations: annotations, bottom: map.bottom, top: map.top, borderwidth: 1 }); if (!isandroid) { map.mapview.addannotation(annotations[0]); } map.mapview.selectannotation(annotations[0]); win.add(map.mapview); }, createoptions: function () { //map/satellite displays. var mapdisplay = new imageview({ image: path + 'images/map/satellite-view.png', width: 70, height: 49, zindex: 2, top: map.top + 5, right: 5 }); mapdisplay.addeventlistener('click', function () { if (map.display == "map") { map.mapview.setmaptype(titanium.map.satellite_type); mapdisplay.image = path + "images/map/map-view.png"; map.display = "satellite"; } else { map.mapview.setmaptype(titanium.map.standard_type); mapdisplay.image = path + "images/map/satellite-view.png"; map.display = "map"; } }); win.add(mapdisplay); //crosshairs. if(ti.geolocation.locationservicesenabled) { var centerdisplay = new imageview({ image: path + 'images/map/crosshairs.png', width: 49, height: 49, zindex: 2, top: map.top + 5, right: 80 }); centerdisplay.addeventlistener('click', function () { if(map.latitude != 0 && map.longitude != 0) { info("setting user location " + map.latitude + " / " + map.longitude); //center map. var userlocation = { latitude: map.latitude, longitude: map.longitude, latitudedelta: map.latitudedelta, longitudedelta: map.longitudedelta, animate: true }; map.mapview.setlocation(userlocation); } else { info("can't user location, lat , long 0!"); } }); win.add(centerdisplay); } }, createannotation: function (title, subtitle, latitude, longitude, islocation, addtomap) { var mapannotation = ti.map.createannotation({ latitude: latitude, longitude: longitude, title: title, subtitle: subtitle, animate: true }); if (isandroid) { mapannotation.pinimage = path + (islocation ? "images/map/blue-pin.png" : "images/map/purple-pin.png"); } else { mapannotation.pincolor = islocation ? ti.map.annotation_purple : ti.map.annotation_red; } if (addtomap) map.mapview.addannotation(mapannotation); return mapannotation; }, updateannotation: function (mapannotation, title, subtitle, latitude, longitude, islocation) { if (mapannotation) { map.mapview.removeannotation(mapannotation); mapannotation = map.createannotation(title, subtitle, latitude, longitude, islocation); map.mapview.addannotation(mapannotation); map.mapview.selectannotation(mapannotation); } }, addannotation: function (mapannotation) { map.mapview.addannotation(mapannotation); }, removeannotation: function (mapannotation) { map.mapview.removeannotation(mapannotation); }, selectannotation: function (mapannotation) { map.mapview.selectannotation(mapannotation); }, createroute: function (name, points) { var route = { name: name, points: points, color: "#7c74d4", width: 4 }; map.mapview.addroute(route); settimeout(function () { map.mapview.regionfit = true; }, 700); }, getlocation: function() { ti.geolocation.preferredprovider = ti.geolocation.provider_gps; ti.geolocation.purpose = "testing"; ti.geolocation.accuracy = ti.geolocation.accuracy_best; ti.geolocation.distancefilter = 10; if(!ti.geolocation.locationservicesenabled) { //alert('your device has gps turned off. please turn on.'); return; } function updateposition(e) { if(!e.success || e.error) { info("unable location - " + e.error); return; } info(json.stringify(e.coords)); map.latitude = e.coords.latitude; map.longitude = e.coords.longitude; ti.geolocation.removeeventlistener('location', updateposition); }; ti.geolocation.getcurrentposition(updateposition); ti.geolocation.addeventlistener('location', updateposition); } };
Comments
Post a Comment