Creating an encoded polygon for google maps in PHP

2.1k views Asked by At

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

2

There are 2 answers

3
geocodezip On BEST ANSWER

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?

0
user1641165 On

Using the previous answer I managed to find a solution which did explain the process and worked quite well.

If others are looking to do the same thing, you can use a script made by Gabriel Svennerberg.

The link is: http://www.svennerberg.com/2008/11/polylines-in-google-maps-part-2/