Question

I am using mapquest for adding new locations with following code from Javascript API.

  window.map = new MQA.TileMap(       /*constructs an instance of MQA.TileMap*/
    document.getElementById('map'),   /*ID of element on the page where you want the map added*/
    7,                                /*intial zoom level of the map*/
    {lat:17.73, lng:83.3}, /*center of map in latitude/longitude */
    'map');                           /*map type (map)*/

    var poi=new MQA.Poi({lat:data.lat, lng:data.lng});
    map.addShape(poi);

Now, what I want is, the map should be center to the newly added POI instead of the default one. I think there might be some API for this, but so far I could not trace it out. Please help me.

Was it helpful?

Solution

You should use

map.setCenter({lat:data.lat, lng:data.lng});

It will work.

OTHER TIPS

What you need to do is call the slideMapToPoint function against the map with the latLng property of your newly created poi object.

// Create new POI
var poi = new MQA.Poi({lat:data.lat, lng:data.lng});
map.addShape(poi);

// Centre the map to the given POI.
map.slideMapToPoint(map.llToPix(poi.latLng));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top