javascriptgoogle-mapsgoogle-maps-static-api

Google Static Maps API Polyline with repeating icon (dashed line)


I have successfully used Google Maps icon technique to create dashed poly lines but now I want to apply this to a Google Maps Static Maps API image.

How do I apply a repeating icon along a path in a static Map similar to how it is done in Google Maps API?

Is it simply adding an icons to the path? For example take a static Map URL that shows a solid path in NY

{"https://maps.googleapis.com/maps/api/staticmap?size=600x600&path=color:0xff0000ff|weight:5|40.737102,-73.990318|40.749825,-73.987963|40.752946,-73.987384|40.755823,-73.986397&zoom=19" + "&key=" + process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY}

Would you just add in icons variable with associated arguments like (icon, offset and repeat) to dash this line?:

{"https://maps.googleapis.com/maps/api/staticmap?size=600x600&path=color:0xff0000ff|weight:5|icons&icon|path=M 0,-1 0,1|strokeopacity:0|scale:2|offset:0|repeat:20px|40.737102,-73.990318|40.749825,-73.987963|40.752946,-73.987384|40.755823,-73.986397&zoom=19" + "&key=" + process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY}

This doesn't work


Solution

  • Icons property for path parameter

    Currently, there is no way to directly apply dashed lines to a Static Maps URL request using the icons property, as you can in the Maps JavaScript API. The Static Maps API has a more limited feature set compared to the interactive JavaScript API.

    Specifically, the icons property which allows you to customize line patterns with symbols, is not available within the Static Maps API's URL parameters. Reference: https://developers.google.com/maps/documentation/maps-static/start#URL_Parameters

    There's an open Feature Request in the Public Issue Tracker that asks a way to customize the path parameter in a Google Maps Static API request in the same way as we can with the Polyline object in Maps JavaScript API. Please see the issue link here: https://issuetracker.google.com/74100392

    You can star the feature request to get updates and leave comments for additional information. As that could help provide valuable feedback on the importance of the feature.

    Please do note that the Issue Tracker is the authoritative source for public information regarding the feature requests, and all publicly-relevant updates will be posted there. So you can post your use case there and star it to get updates.