Skip to content
This repository was archived by the owner on Sep 4, 2021. It is now read-only.
This repository was archived by the owner on Sep 4, 2021. It is now read-only.

get the locality of the place #79

Open

Description

@bbeckk

Why does it gives 10 outcomes in the following code? How can I get the city name only? I've tested in android devices.

	var NY = {
	  lat: 40.7809261,
	  lng: -73.9637594,
	};

	export default class App extends Component<Props> {


	  currentArea = () => {
		Geocoder.geocodePosition(NY).then(res => {
			console.log('position', res);
		})
		.catch(err => console.log(err))
	  }
	  render() {
		return (
		  <View>
			<TouchableOpacity
			  onPress={() => this.currentArea()}
			>
			  <Text>Get current location</Text>
			</TouchableOpacity>
		  </View>
		);
	  }
	}

Debugged value:

position 
(10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0
:
{streetName: "East Drive", feature: null, locale: "en_GB", locality: "New York", position: {…}, …}
1
:
{streetName: null, feature: "Central Park", locale: "en_GB", locality: "New York", position: {…}, …}
2
:
{streetName: null, feature: "Manhattan", locale: "en_GB", locality: "New York", position: {…}, …}
3
:
{streetName: null, feature: null, locale: "en_GB", locality: "New York", position: {…}, …}
4
:
{streetName: null, feature: "10028", locale: "en_GB", locality: "New York", position: {…}, …}
5
:
{streetName: null, feature: "New York County", locale: "en_GB", locality: "New York", position: {…}, …}
6
:
{streetName: null, feature: "New York-Northern New Jersey-Long Island, NY-NJ-PA", locale: "en_GB", locality: null, position: {…}, …}
7
:
{streetName: null, feature: "New York Metropolitan Area", locale: "en_GB", locality: null, position: {…}, …}
8
:
{streetName: null, feature: "New York", locale: "en_GB", locality: null, position: {…}, …}
9
:
{streetName: null, feature: "United States", locale: "en_GB", locality: null, position: {…}, …}
length
:
10
__proto__
:
Array(0)

Activity

  1. bkspace commented on Jul 22, 2018

    @bkspace

    For Android - this library uses Geocoder under the hood.

    Returns an array of Addresses that are known to describe the area immediately surrounding the given latitude and longitude.
    

    You could use res[0].country for example.

  2. bbeckk commented on Jul 23, 2018

    @bbeckk
    Author

    Thankyou.. @bkspace I just wonder why it gives an array with 10 different objects?

  3. bkspace commented on Jul 23, 2018

    @bkspace

    I don’t think I know the exact answer to that - other than geocoding is hard and the backend services will try and ‘estimate’ your location

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions