Search code examples
google-mapsgoogle-polyline

Draw google polyline with line width set in meters


I noticed that when you draw a polyline in google maps you set it's width in pixels (strokewidth). Is there a way I could set that in metres instead?


Solution

  • Unfortunately, I don't know any easy way to do this. The API does not appear to have documentation on this and I assume this feature is unsupported.

    One problem is that the pixels represent a different number of meters at different zoom levels within the API. So it would be a dynamic quantity if the zoom levels are changed.

    One option might be to compute the width in pixels for representing a given number of meters for a given zoom level. For that, you would have to write your own function based on the scales of the map at each zoom level. That data appear to be available here:

    http://webhelp.esri.com/arcgisserver/9.3/java/index.htm#designing_overlay_gm_mve.htm

    20 : 1128.497220
    19 : 2256.994440
    18 : 4513.988880
    17 : 9027.977761
    16 : 18055.955520
    15 : 36111.911040
    14 : 72223.822090
    13 : 144447.644200
    12 : 288895.288400
    11 : 577790.576700
    10 : 1155581.153000
    9  : 2311162.307000
    8  : 4622324.614000
    7  : 9244649.227000
    6  : 18489298.450000
    5  : 36978596.910000
    4  : 73957193.820000
    3  : 147914387.600000
    2  : 295828775.300000
    1  : 591657550.500000
    

    you can then set the pixel value dynamically depending on the meters you are trying to represent and the current zoom level.

    There may still be a problem because the pixel sizes you generate, may not correspond to the screen pixel sizes, depending on how the API deals with screen DPI and resolution