Search code examples
phpgoogle-mapsgoogle-maps-api-3google-maps-static-api

Creating an encoded polygon for google maps in PHP


I'm just wondering how I can convert points into an encoded polygon for static google maps.

I will be retrieving the data from MySQL as a multipolygon, however I can rearrange the data as needed.

I simply need a good php script that can encode the polygon.

I realize this may seem like a duplicate question, but I have searched everywhere and cannot find anything. There are multiple scripts on-line however there is no documentation as how the array of points is to be formatted and ect.

These include

OR

Thanks


Solution

  • the definitive reference: http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/

    With a link to a PHP implementationby Jim Hribar

    you asked: How do I format it. e.g array(array(xcoord,ycoord),array(xcoord,ycoord));

    Looking at the source of both the examples you reference, I see something like this: (from the second):

     $lat = $points[$i][0];
     $lng = $points[$i][1];
    

    What else do you need to know?