Encoded Polylines Using JQuery

I was given some encoded polylines to display on a google map. However, I use jQuery for many front-end functions, and now I'm trying to find the correct syntax for displaying encoded polylines using jQuery. The standard syntax for adding an encoded polyline is

var polyline = new GPolyline.fromEncoded({ color: "#0000ff", weight: 4, opacity: 0.8, points: "_gkxEv}|vNM]kB}B}@ q@YKg @ IqCGa@EcA ?c", levels: " P@B @ D??@ @?D?CA?B", zoomFactor: 2, numLevels: 18 }); map.addOverlay(polyline); 

Obviously this does not work with jQuery. to add a regular polyline using jQuery which you use

 new google.maps.Polyline({ path: stationPathCoordinates1, strokeColor: "#20B5B3", strokeOpacity: 1.0, strokeWeight: 4 

Where StationPathCoordinates is an array of longs and lats. Now I have this array in an encoded polyline. I suggested that this might be the new google.maps.Polyline.fromEncoded, but this does not work. Does anyone know the syntax of this in jQuery or if possible?

Thanks in advance

+6
jquery jquery-ui maps
source share
2 answers

As @belugabob already noted, there should be no conflict with jQuery at all when using APIs such as the JavaScript APIs for Google Maps.

Nevertheless, and without seeing a complete example, I can only deduce the following:

So, if you need to support the use of encoded polylines, you have two options:

  • Continue to use the V2 API, which assumes your first piece of code is working as it should; you will need to provide more detailed information so that we can find out what is wrong with your code (since jQuery is most likely not to blame here!), two points up though:

    • Best guess : the combination of the API version and your comment regarding the belugabobs question indicate that you can simply skip some or include the wrong dependencies!

    • Another observation: at least according to the Polyline Encoder Interactive Utility, the encoded points and levels in your first code snippets do not match.

  • Upgrade the V3 API, which involves decoding your encoded polylines to Array or MVCArray of LatLng . I don't know an official example, but for a starting point, can you see Esas answer in Encoded Polylines ? , which points to the decodeLine() function in the source code of the Google Polyline Utility, as well as a sample decoder.

Good luck

+5
source share

There seems to be some support for coded polylines now.

http://code.google.com/apis/maps/documentation/javascript/reference.html#encoding

The documentation is not great, but I also found an example here:

http://code.google.com/apis/maps/documentation/javascript/examples/geometry-encodings.html

to give you an idea of ​​how to do this.

0
source share

All Articles