Geo Code Lat Long Mismatch from request
ashokpokharel977 opened this issue · comments
Ashok Pokharel commented
Thanks for the awesome project.
Stumbled into an issue where the request lat long differs from the response
Implementation
export const getAddressFromLatLon = (lat, lon) => {
console.log("Sent Lat long");
console.log("Lat : ", lat);
console.log("Lng : ", lon);
return new Promise(function (resolve, reject) {
geocoder.reverse({ lat: lat, lon: lon }, function (err, res) {
if (err) {
resolve("");
} else {
console.log("Reverse Gocoder Response: ", res);
let city = res[0].city;
let formattedAddress = res[0].formattedAddress;
let addressData = res[0].extra;
let sublocality_level_1 = addressData.sublocality_level_1;
let route = addressData.route;
let premise = addressData.premise;
let subpremise = addressData.subpremise;
let bestAddress = "";
if (route !== null) {
bestAddress =
route +
(sublocality_level_1 !== null ? ", " + sublocality_level_1 : "") +
(premise !== null ? ", " + premise : "") +
(subpremise !== null ? ", " + subpremise : "") +
(city !== null ? ", " + city : "");
} else {
bestAddress =
formattedAddress.toString().split(",")[0] +
(sublocality_level_1 !== null ? ", " + sublocality_level_1 : "") +
(premise !== null ? ", " + premise : "") +
(subpremise !== null ? ", " + subpremise : "") +
(city !== null ? ", " + city : "");
}
console.log("Best Address Location :", bestAddress);
resolve(bestAddress);
}
});
});
};
Request Lat Longs
Sent Lat long
Lat : 27.6720744
Lng : 85.42810229999999
Response
Reverse Gocoder Response:
[
{
formattedAddress: 'Unnamed Road, Bhaktapur 44800, Nepal',
latitude: 27.6721454,
longitude: 85.42813939999999,
extra: {
googlePlaceId: 'ChIJIwbrk68a6zkR3k9u7g4Y7Ug',
confidence: 0.7,
premise: null,
subpremise: null,
neighborhood: 'Bhaktapur',
establishment: null,
sublocality_level_1: null,
route: null
},
administrativeLevels: {
level2long: 'Bagmati',
level2short: 'Bagmati',
level1long: 'Central Development Region',
level1short: 'Central Development Region'
},
streetName: 'Unnamed Road',
city: 'Bhaktapur',
country: 'Nepal',
countryCode: 'NP',
zipcode: '44800',
provider: 'google'
}
]
The response returned the lat long which is different from the request.