Reputation: 688
I am trying to get formatted_address from give lat, lng but I am faced with error "Assertion failed: InvalidValueError: in property latLng: not a LatLng or LatLngLiteral: in property lat: not a number" Iam using GMap.js Below is my code: First I get current location of user
GMaps.geolocate({
success: function (position) {
getSetFormattedAddressLatLng( {
H: position.coords.latitude,
L: position.coords.longitude
});
},
error: function (error) {
notificationService.error('Geolocation failed: ' + error.message);
},
not_supported: function () {
alert("Your browser does not support geolocation");
},
always: function () {
//alert("Done!");
}
});
On success to get current location of the user I call function getSetFormattedAddressLatLng(), the funciton looks as below
function getSetFormattedAddressLatLng(latLng) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
latLng: latLng
}, function (responses) {
if (responses && responses.length > 0) {
//set the formatted_address on originOrDestination
} else {
debugger;
notificationService.error('Cannot determine address at this location.');
}
});
}
But when I call geocoder.geocoder() I get the error message "Assertion failed: InvalidValueError: in property latLng: not a LatLng or LatLngLiteral: in property lat: not a number". What am I doing wrong?
Regards, Chidan
Upvotes: 1
Views: 3929
Reputation: 688
Thanks for hint from Duncan, solved it. solved by creating latLng object as below and then passing it to geocoder.geocode()
var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
Upvotes: 0
Reputation: 31912
You're passing a structure like this to the geocoder.geocode
constructor:
{
H: position.coords.latitude,
L: position.coords.longitude
}
Which isn't valid. Try just doing this (I'm assuming position
is already a LatLng object):
getSetFormattedAddressLatLng(position);
or possibly
getSetFormattedAddressLatLng(position.coords);
At the very worst, you could create a new LatLng object:
GMaps.geolocate({
success: function (position) {
getSetFormattedAddressLatLng(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));
},
Upvotes: 0