Giter Site home page Giter Site logo

Access Places Data about react-geosuggest HOT 7 CLOSED

ubilabs avatar ubilabs commented on July 18, 2024
Access Places Data

from react-geosuggest.

Comments (7)

ro-ka avatar ro-ka commented on July 18, 2024

The results vary slightly, depending whether it is a predefined result or a Google Maps API result.

A predefined result looks like this:

{
  "label": "Rio",
  "placeId": "Rio",
  "location": {
    "lat": -22.066452,
    "lng": -42.9232368
  }
}

A Google Maps result looks like this:

{
  "label": "Rio de Janeiro, Brazil",
  "placeId": "ChIJw4riypQYmAAR0IMFwRrDSQM",
  "location": {
    "lat": -22.9068467,
    "lng": -43.17289649999998
  }
}

So the only difference is the placeID. It is either the predefined one or the Google Maps one. Would you prefer to get the complete Google Maps result just like in the geocomplete plugin (which is by us, too ;) )? Also, not sure how to handle the placeId. Return as null when not a Google Maps result?

You can check the results by opening the console and selecting results.

from react-geosuggest.

AdamBrodzinski avatar AdamBrodzinski commented on July 18, 2024

Ahhh, that makes a lot of sense now! I didn't realize the geocomplete and places API's were separate.
From the readme I thought it was supposed to fetch the places data too, not just the long/lat.

If I used this repo and had the ID or Long/Lat, would i then make an additional call to Google Places to get the full street_address, country, administrative_area_level_1, etc...data?

Basically i'm dropping my old templating language for React and the last thing stopping me is to replace the GeoComplete so that I can search for an address, click it, and autofill some form fields as needed. (Actually using Geocomplete after React's render may work out of the box since I still have jQuery.. haven't tried yet).

from react-geosuggest.

ro-ka avatar ro-ka commented on July 18, 2024

Just checked. First there is the autocomplete request to the places API. That returns something like this:

[
  {
    "description":"NYC, NY, United States",
    "id":"7eae6a016a9c6f58e2044573fb8f14227b6e1f96",
    "matched_substrings":[
      {"length":3, "offset":0}
    ],
    "place_id":"ChIJOwg_06VPwokRYv534QaPC8g",
    "reference":"CmRYAAAAmsOZZgKoe5We5NX8Wfi0mzv9F3n2FqRMxMlOyna0dFW_QYXRI5u8gymVeR6xE8dfAmmUI3eDitA590MQs7G26Nl4z2NdA3amkdxL4UjgE-Sfms0wYXNbb_AdP9gMpCmlEhD4NqvTIcFJp27tAfvMCCzQGhTJ7dbZPhDw9ZvR4gaVEYpNzmPJYA",
    "terms":[
      {"offset":0, "value":"NYC"},
      {"offset":5, "value":"NY"},
      {"offset":9, "value":"United States"}
    ],
    "types":[
      "locality",
      "political",
      "geocode"
    ]
  },
  …
]

As there is no location data in that response, when selecting a suggestion later, there is a geocoding request. That geocoding request returns all the information you mentioned. Currently it gets filtered and only the location is returned.

I could add all the other data, too. Would keep the .location, too for not breaking. The complete Google Geocoding response data could be added at .gmaps. It would only be present when a geocoding was necessary. For presets this won’t apply when initialized with a location. What do you think?

from react-geosuggest.

ro-ka avatar ro-ka commented on July 18, 2024

Complete places data is now available and documented: https://github.com/ubilabs/react-geosuggest#onsuggestselect

Thanks for reporting! Hope this helps in converting your app.

from react-geosuggest.

ro-ka avatar ro-ka commented on July 18, 2024

P.S.: Released as 1.2.0.

from react-geosuggest.

AdamBrodzinski avatar AdamBrodzinski commented on July 18, 2024

Hey thanks @ro-ka !! 🍻

Keeping the location is ideal too since I can save that data to Mongo and use their Geospatial query when needed!

giphy

from react-geosuggest.

ro-ka avatar ro-ka commented on July 18, 2024

Great to hear! πŸ˜„

from react-geosuggest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.