Using Longitude/Latitude as Waypoint – Even if we have a good project plan and a logical concept, we will spend the majority of our time correcting errors abaout javascript and google-maps. Furthermore, our application can run without obvious errors with JavaScript, we must use various ways to ensure that everything is operating properly. In general, there are two types of errors that you’ll encounter while doing something wrong in code: Syntax Errors and Logic Errors. To make bug fixing easier, every JavaScript error is captured with a full stack trace and the specific line of source code marked. To assist you in resolving the JavaScript error, look at the discuss below to fix problem about Using Longitude/Latitude as Waypoint.
Problem :
I’m trying to use the longitude latitude as a waypoint in my google maps and cant seem to get it working.
Here’s how I have my values pushed
waypts_mtlsheloc.push({
location: (45.658197,-73.636333), //I don't think I'm supposed to write this like that. But can't find the right way.
stopover: true
})
And then try to modify my line like this
service.route({
origin: latlng_mtlsheloc[0],
destination: latlng_mtlsheloc[latlng_mtlsheloc.length - 1],
waypoints:waypts_mtlsheloc,
travelMode: google.maps.DirectionsTravelMode.DRIVING
}, function(result, status) {
console.log(status)
if (status == google.maps.DirectionsStatus.OK) {
path = path.concat(result.routes[0].overview_path);
line_mtlsheloc.setPath(result.routes[0].overview_path);
}
});
But it gives me an error “Error in property [waypoint]”, I’ve tried different methods of writing down the location, but can’t seem to find the right one.
Solution :
To use a latitude and longitude as a waypoint, it must be a google.maps.LatLng object
(the documentation says a string or a LatLng; string is an address, LatLng is geographic coordinates)
waypts_mtlsheloc.push({
location: new google.maps.LatLng(45.658197,-73.636333),
stopover: true
})
code snippet: