google-mapsgoogle-maps-static-api

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


Solution

  • 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