I am using google encoding libraries to encode and decode path points array, like below:
To encode:
var encodedPath = google.maps.geometry.encoding.encodePath(path);
To decode:
var decodedPath = google.maps.geometry.encoding.decodePath(encodedPath);
However I found the encoding libraries is not consistently loaded every time. Sometimes the libraries only loads up to maps, as I printed out below:
showRouteFor(): google = [object Object]
showRouteFor(): google.maps = [object Object]
showRouteFor(): google.maps.geometry = undefined
using the below piece of JS code:
console.log("showRouteFor(): google = " + google);
if(google != null) {
console.log("showRouteFor(): google.maps = " + google.maps);
if(google.maps != null) {
console.log("showRouteFor(): google.maps.geometry = " + JSON.stringify(google.maps.geometry));
if(google.maps.geometry != null) {
console.log("showRouteFor(): google.maps.geometry.encoding = " + JSON.stringify(google.maps.geometry.encoding));
}
}
}
Other times the libraries load ok and thus I can use it to decode the path.
What can be the reason?
Thank you for your time.
Make sure you load the library by URL.