3

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

ylecuyer
  • 312
  • 2
  • 17
  • I think your current custom marker image has a shadow as ["Marker shadows were removed in version 3.14 of the Google Maps JavaScript API. Any shadows specified programmatically will be ignored."](https://developers.google.com/maps/documentation/javascript/markers#complex_icons) As for supporting details,here is a previous SO question regarding [marker shadows](http://stackoverflow.com/questions/18470063/shadows-on-google-maps-visualrefresh). And in the example for [custom icon](https://developers.google.com/maps/documentation/static-maps/intro#CustomIcons) there is no shadows.I hope this helps – Mr.Rebot May 08 '16 at 13:22
  • It seems that the french documentation hasn't been updated (I reported that to google). Nevertheless the english one states that: "The anchor point of a custom icon is set as the center of the image." which is no the case if I remove the shadow parameter – ylecuyer May 08 '16 at 14:29
  • What is `url` in your posted snippet? Please provide a [Minimal, Complete, Tested and Readable example](http://stackoverflow.com/help/mcve) that demonstrates the issue. – geocodezip May 08 '16 at 18:44
  • The `url` is `http://g oo.gl/fMjXd2` (stackoverflow does'nt allow short url to be posted) – ylecuyer May 08 '16 at 18:46
  • Possibly related issue in the issue tracker [Issue 6126: Bug: Markers anchor point behaviour changed](https://code.google.com/p/gmaps-api-issues/issues/detail?id=6126) (is marked obsolete) – geocodezip May 08 '16 at 18:53
  • 2
    Feature request: [Issue 2185: Anchor Position on Custom Markers](https://code.google.com/p/gmaps-api-issues/issues/detail?id=2185) – geocodezip May 08 '16 at 18:55
  • possibly related issue in the issue tracker: [Issue 6104: Bug: Custom icons started showing at wrong location, without shadow](https://code.google.com/p/gmaps-api-issues/issues/detail?id=6104) – geocodezip May 08 '16 at 18:56
  • 1
    Created an [issue in the tracker: Issue 9713: Bug: Custom Icons anchor in wrong place per documentation](https://code.google.com/p/gmaps-api-issues/issues/detail?id=9713) – geocodezip May 08 '16 at 19:01
  • For those interested on the issue, A fix has been provided by Google, it's simply a change in the documentation which states: "The anchor point of a custom icon is set as the bottom center of the image.".... Better to say that this is not the intended fix. https://code.google.com/p/gmaps-api-issues/issues/detail?id=9713 – ylecuyer Jul 25 '16 at 01:20

2 Answers2

2

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

Akos Cz
  • 12,711
  • 1
  • 37
  • 32
xomena
  • 31,125
  • 6
  • 88
  • 117
0

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.

Soldeplata Saketos
  • 3,212
  • 1
  • 25
  • 38