ylecuyer
ylecuyer

Reputation: 302

Custom icon anchor point in google maps static API

I try to set the anchor point of my custom marker to the center with the shadow:false parameter but it seems to be ignored:

This is the image without custom marker:

https://maps.googleapis.com/maps/api/staticmap?size=1024x512&path=weight:3|color:0x000000FF|enc:apeiH_h_M{H}LqFjJ_CkFsB_H}@mFUcG]qFm@mt@uM\&markers=48.85777,2.2952&markers=48.86493,2.31033

without custom marker The same image with the custom marker and no shadow parameter:

https://maps.googleapis.com/maps/api/staticmap?size=1024x512&path=weight:3|color:0x000000FF|enc:apeiH_h_M{H}LqFjJ_CkFsB_H}@mFUcG]qFm@mt@uM\&markers=icon:url|48.85777,2.2952&markers=48.86493,2.31033

enter image description here

The same image with the custom marker and shadow parameter set to false:

https://maps.googleapis.com/maps/api/staticmap?size=1024x512&path=weight:3|color:0x000000FF|enc:apeiH_h_M{H}LqFjJ_CkFsB_H}@mFUcG]qFm@mt@uM\&markers=shadow:false|icon:url|48.85777,2.2952&markers=48.86493,2.31033

enter image description here

Upvotes: 3

Views: 1859

Answers (2)

xomena
xomena

Reputation: 32100

On January 27, 2017 Google reported that issue 2185 has been fixed. So, from now on you can define a position of anchor for custom markers in Static Maps API.

The documentation was also updated:

You may specify an anchor point for the custom icon. The anchor point sets how the icon is placed in relation to the specified markers locations. By default, the anchor point of a custom icon is the bottom center of the icon image. You can specify a different anchor point using the anchor descriptor in conjunction with your icon. Set the anchor as an x,y point of the icon (such as 10,5), or as a predefined alignment using one of the following values: top, bottom, left, right, center, topleft, topright, bottomleft, or bottomright.

https://developers.google.com/maps/documentation/maps-static/start#CustomIcons

So you can rewrite your example now as

https://maps.googleapis.com/maps/api/staticmap?size=640x512&path=weight:3|color:0x000000FF|enc:apeiH_h_M{H}LqFjJ_CkFsB_H}@mFUcG]qFm@mt@uM\&markers=anchor:center|icon:http%3A%2F%2Fgoo.gl%2FavYzpd|48.85777,2.2952&markers=48.86493,2.31033&center=48.85777,2.2952

centeredImage

Upvotes: 2

Soldeplata Saketos
Soldeplata Saketos

Reputation: 3461

How about setting a centerparameter in your query?

https://maps.googleapis.com/maps/api/staticmap?size=640x512&path=weight:3|color:0x000000FF|enc:apeiH_h_M{H}LqFjJ_CkFsB_H}@mFUcG]qFm@mt@uM\&markers=icon:http%3A%2F%2Fgoo.gl%2FavYzpd|48.85777,2.2952&markers=48.86493,2.31033&center=48.85777,2.2952

result: centeredImage

Even though the map is actually centered, The icon is not upon the starting place... this should be fixed somehow. :/

EDIT
So... here you have my very ugly workaround: just re-set your marker's Lat value. By try and error I got this:

https://maps.googleapis.com/maps/api/staticmap?size=640x512&path=weight:3|color:0x000000FF|enc:apeiH_h_M{H}LqFjJ_CkFsB_H}@mFUcG]qFm@mt@uM\&markers=icon:http%3A%2F%2Fgoo.gl%2FavYzpd|48.857,2.2952&markers=48.86453,2.31033

With this result: uglyWA

Apparently, with this level of zoom and with my particular icon, it's been enough with a subtraction of 0.00077 in the Lat value of the marker.

FINAL CONCLUSION

Actually there is no way to center the image right from the URL request. On the other hand, we can draw custom icons that fit our purposes. Just adding some margin up in the icon (transparent space) should make the trick.

Upvotes: 0

Related Questions