Draw Map from Curren zoom, Location

You must Login before you can answer or comment on any questions.

I have a map object, which has a map with a annotation on it. So I have zoomed in a bit, and positioned the map, as I want to use that state as the default map when it loads.

So I am using 'regionChanged' to determine zoom, and location.

this.the_map = central.drawMap(this, 0.05, 0.05);
 
Central.prototype.centreMap = function(parent_obj, location, zoom_lat, zoom_long) {
    parent_obj.setLocation({
        longitude : location.lng,
        latitude : location.lat,
        animate : true,
        latitudeDelta : zoom_lat,
        longitudeDelta : zoom_long
    });
}
 
Central.prototype.drawNationalPark = function(parent_obj, location, name) {
    parent_obj.the_map.removeAllAnnotations();
 
    /*
     * Add Map Tray
     */
    central_object.removeMapTray(parent_obj);
    central_object.addMapTray("", parent_obj, "");
 
    /*
     * Add the Service tray
     */
    central_object.removeServiceTray(parent_obj);
    central_object.addServiceTray("", "", parent_obj);
 
    var the_pin = Ti.Map.createAnnotation({
        title : name,
        latitude : location.lat,
        longitude : location.lng,
        image : dir_path.R + "images/location/orange_google_flag.png",
        animate : true
    });
 
    parent_obj.the_map.addAnnotation(the_pin);
 
    var location_object = new Object();
    location_object.lat = location.lat_centre;
    location_object.lng = location.lng_centre;
    central_object.centreMap(parent_obj.the_map, location_object, location.latDelta, location.lngDelta);
}
Now when I used the values fetched form the 'regionChanged' event in the 'location' object (in code) , the map rendered is not the same as what I saw on the screen.

How can I achieve this.

ps: The 'regionChanged' event seems to change the zoom. How can I prevent this?

Thanks in Advance.

1 Answer

Hi Steven

You have not included your code for the regionChanged so it is hard to work out what may be happening.

Also just for clarity you understand that

latitudeDelta : zoom_lat,
longitudeDelta : zoom_long
Control the 'zoom' but in fact they are really just distances in both axis? (Not trying to teach you to suck eggs - just want to make sure we are both on the same page).

— answered 10 months ago by Malcolm Hollingsworth
answer permalink
1 Comment
  • this.the_map.addEventListener('regionChanged', function(e) {
            central.printObject(e);
        });
    This will just print out the event object which tells me the delta, and location info.
    Central.prototype.centreMap = function(parent_obj, location, zoom_lat, zoom_long) {
        parent_obj.setLocation({
            longitude : location.lng,
            latitude : location.lat,
            animate : true,
            latitudeDelta : zoom_lat,
            longitudeDelta : zoom_long
        });
    }
    This is the thing which sets the location. But I am going crazy trying to get some start up states for a few maps. Shouldn't be this hard.

    — commented 10 months ago by Steven Marshall

Your Answer

Think you can help? Login to answer this question!