marlove / react-native-geocoding

MIT License
208 stars 54 forks source link

Feature: Support for address searching within a geolocation context (biased bounds) #28

Closed IjzerenHein closed 3 years ago

IjzerenHein commented 4 years ago

Hi, first of all thanks for this lib 👍 👍

This PR adds support for the bounds parameter for address based searches. https://developers.google.com/maps/documentation/geocoding/intro?hl=pt#Viewports

This makes it possible to bias your searches to look in a certain area (e.g. your current location), instead of searching globally. This generally improves the quality of the results when you want to search in your current area.

The API has been extended to support an optional second parameter when the first argument is a string.

The second argument should be a bounds object with the following layout:

type BoundsType = {
  southeast: {
    lat: number,
    lng: number
  },
  northeast: {
    lat: number,
    lng: number
  }
}

Usage of extended API:

Geocoder.from("Pyramid", {
        southwest: {lat: 36.05, lng: -115.25},
        northeast: {lat: 36.16, lng: -115.10}})
        .then(json => {
            var location = json.results[0].geometry.location;
            console.log(location);
        })
        .catch(error => console.warn(error));

Works like a charm. Let me know if you have any questions.

cheers, Hein

Cplantijn commented 4 years ago

This is a fantastic feature! Any reason why this PR is still pending?