1

I using mapbox to show a map in my app but I need show a location using a addres, so I use the geocoder to convert the address in coordinates but these coordinates that I get are wrong, when a print these in the map, the map show me other place, in Android is not too bad but in IOS is terrible, sometimes the map show me a place at the other side of the city. I already tried using the coordinates that I know are correct and the map shows them well, so the problem would be the geocoder.

I tried use the Google Maps API but the form to write thee address is very strange I dont understand

What lib i can use but get the exact coordinates?

WI HERMES
  • 11
  • 1
  • 3
  • Try using Google Geocoding API, you can send in Address to get Coordinates or Coordinates to get address of location, using this API. The API uses GET request and is pretty fast too. – Hisham Mubarak Jan 31 '18 at 19:20
  • But i need exact addres, example, "Cra 53#15-56, Cali": https://maps.googleapis.com/maps/api/geocode/json?address=Cra+53+#15+56,+Cali,+CO&key=..... it brings me too many values and only 2 correspond to my city – WI HERMES Jan 31 '18 at 20:05

1 Answers1

-2

You can use Geocoder to get the coordinates e.g.

this.watchId = navigator.geolocation.watchPosition(
                (position) => {
                    this.setState({
                        latitude: position.coords.latitude,
                        longitude: position.coords.longitude,
                        error: null,
                    });
                },

This function will return the coordinates . If you get the coordinates you can call google API service to get the complete address of your street.

fetch('https://maps.googleapis.com/maps/api/geocode/json?address=' + lat + ',' + long + '&key=' + 'API_KEY')
        .then((response) => response.json())
            .then((responseJson) => {
            alert('error')
            alert('ADDRESS GEOCODE is BACK!! => ' + JSON.stringify(responseJson));
})
fewlinesofcode
  • 3,007
  • 1
  • 13
  • 30
Roshna
  • 1
  • Please try to nicely format the answer. Also, it would be helpful if you could mention which libraries to import. – B--rian Nov 21 '18 at 09:34