简体   繁体   中英

mapquest pointing to center the map for a POI in Javascript API

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.

You should use

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

It will work.

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM