Set map zoom level
I have a mapView and on the click of a button, want it to reset to a specific zoom level, is there a property for this (I can't see one in the API docs, unless I have misunderstood one).
I currently use mapView.zoom(x) but this is relative to current zoom level.
Thanks,
Dan
8 Answers
-
Hey Dan,
I think that you can zoom into a specific level by settin latitudeDelta and longitudeDelta ex:var mapview = Titanium.Map.createView({ mapType: Titanium.Map.STANDARD_TYPE, region: {latitude:45.46411, longitude:9.19193, latitudeDelta:0.05, longitudeDelta:0.05}, animate:true, regionFit:true, userLocation:true }); win2.add(mapview);
-
Thanks for that Nicolo, a little stuck on how to impliment that at the moment. I have a click listener setup for a button as the map already exists and is displayed. My code is something like:
mapView.region = {latitude:mapLatitude, longitude:mapLongitude, latitudeDelta:0.05, longitudeDelta:0.05}; mapView.animate = true;
But I get the useful 'stopped unexpectedly' error message. Have I set the variable wrong in here, I tried several variations, but didn't hit upon one that did the trick.
-
Still having difficulty with this, anyone got some advice on what I could try next?
-
I haven't tested it, but you could try setting the region back to its original setting.
-
Don, sadly that still gave me the 'stopped unexpectedly' error. I tried putting the below within the click handler:
mapOverlayLink.addEventListener('click',function(e) { Titanium.API.info("Latitude: " + mapLatitude); Titanium.API.info("Longitude: " + mapLongitude); var mapWindow = Ti.UI.createWindow({title:'Map'}); var mapView = Titanium.Map.createView({ mapType: Titanium.Map.STANDARD_TYPE, region: {latitude:50, longitude:0, latitudeDelta:0.001, longitudeDelta:0.001}, animate:true, regionFit:true, userLocation:true }); mapWindow.add(mapView); mapWindow.open(); });
The region setting are identical to the ones initially used when the map is created in the first place, but errors when I try to run it again as an update.
-
Haha, got it today, it wasn't region which I needed to use, it was location. Not sure I quite get the difference between the 2, but this one appears to work nicely.
mapView.location = {latitudeDelta:0.05, longitudeDelta:0.05};
Although sadly it seems to only run it once, if I were to then zoom out again, it wont rerun for some reason.
-
Hey Dan ,
I think that if u have a click listener set up for a button u have to redeclare the mapview variable try this:button.addEventListener('click',function(e) { var w = Ti.UI.createWindow({title:'Map'}); var mapview = Titanium.Map.createView({ mapType: Titanium.Map.STANDARD_TYPE, region: { latitude:mapLatitude, longitude:mapLongitude, latitudeDelta:0.05, longitudeDelta:0.05}, animate:true, regionFit:true, userLocation:true }); w.add(mapview); w.open(); });
-
Hi Nicolo, gave that a go this morning, and sadly I am getting the same error message coming up:
mapOverlayLink.addEventListener('click',function(e) { Titanium.API.info("Latitude: " + mapLatitude); Titanium.API.info("Longitude: " + mapLongitude); var mapWindow2 = Ti.UI.createWindow({title:'Map'}); var mapView2 = Titanium.Map.createView({ mapType: Titanium.Map.STANDARD_TYPE, region: {latitude:mapLatitude, longitude:mapLongitude, latitudeDelta:0.05, longitudeDelta:0.05}, animate:true, regionFit:true, userLocation:true }); mapWindow2.add(mapView2); mapWindow2.open(); });
The Lat/Long variables are populated so I don't think that is the issue (although I did also test with hard numbers, and still got the error). The view is also identical pretty much to how it was added originally (otherthan the number 2 on the variable name).
The window display if empty, so it's to do with the map somehow, is it that I need to close the other mapView first do you think, if so, how to I do that, is it just .close()?