peter.o
peter.o

Reputation: 3530

MapQuest JS API - How to position custom marker icon

I'd like to position my custom marker on MapQuest, because location is poiting at the middle of the icon, not at the bottom of the icon (icon is a image of "pin").

var icon=new MQA.Icon("/images/market.png",30,70);
    locator.setIcon(icon);
    map.addShape(locator);

Thanks a lot in advance

Upvotes: 2

Views: 2136

Answers (1)

jharahush
jharahush

Reputation: 767

Disclaimer: I work for MapQuest.

You can position custom icons using the setIconOffset method on your POI. Here's a quick example:

var myIcon=new MQA.Poi( {lat:39.739217, lng:-104.984861} );
myIcon.setIcon(new MQA.Icon('img/arrowicon.png', 72, 87));
myIcon.setIconOffset(new MQA.Point(-43,-72));

The first number you pass into MQA.Point is essentially the CSS left offset of the icon, while the second is the top.

If you need help, don't hesitate to comment back or check out the Forums on the MapQuest Developer Network.

Upvotes: 5

Related Questions