Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geo Code Lat Long Mismatch from request #307

Open
ashokpokharel977 opened this issue Aug 9, 2020 · 0 comments
Open

Geo Code Lat Long Mismatch from request #307

ashokpokharel977 opened this issue Aug 9, 2020 · 0 comments

Comments

@ashokpokharel977
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant