Hi. I’m trying to get longitude and latitude coordinates from a given address but I’m having issues with getting the coordinates. I used this website (Overview | Geocoding API | Google Developers) but I still have issues.![|624x443]
That’s my code. Hospital’s text is the address and TitleL is just a label to which I update it’s contents to the coordinates to see if my code is working. Any suggestions will be appreciated! Thanks!
Please see my tutorial video and post about how to ask for help with APIs:
One thing I mention is that it’s helpful if you post the URL you are using and also the full text of a sample JSON response.
I would be surprised if you could get a property from the JSON response that contains any text you type into a text input component. So that’s at least one thing that will need to change. That kind of information would usually be included in the URL itself.
The other thing to keep in mind when troubleshooting something like this is to put each data value into a separate label and make sure they are what you expect them to be. So that means checking the value of the longitude and latitude before worrying about whether or not they work in a Map component. And also doing error checking. My video explains that as well.
Hi. This really helped me understand JSON and how to use WEB API. So, thank you for that. But do you have any recommendations of which database for me to use if I want to find the coordinates of an address that the user inputs? By database I mean like the /v2/measurements that was used in the video. If there is no database available, could you please send a video of how to find a locationID of a given address? Thanks!
You’re welcome! What you’re wanting to do is called geocoding. It looks like you’re already working with the Google Maps Geocoding API. If you look at the sample request and response on that page, it should give you an idea about how to get started creating a url that works in a browser (always step 1 of working with an API!):
Thanks for replying! I figured out the issue. Its with my API Key. I tried looking for some other API Keys but when I test them out by putting the complete URL in the URL section of Google, I get a message saying that the API key is invalid. I have right now hardcoded an address since I’m currently just trying to make to make it work with hardcoded addresses and will later go on to the address the user inputs. Do you have any suggestions with where to get a valid API KEY? Thanks so much for helping, I really appreciate it.
Thank you so much for your time and patience! I got it work so that it marks the longitude and latitude of any given address! However, it marks any address. Like if I type 850, it actually marks an address. Is that something I can fix or would that just be the user’s fault in the end? Thank you so much for helping me out! You don’t know how much I was struggling on this!
So you’re saying that the Google Maps API returns a lat/long pair for anything you type in? If that’s true then there is probably a JSON property that has a value that indicates whether or not the address is valid.
Can you post the full text of the JSON response you get when you type in “850”?
Wow, you’re right. “850” returns a valid JSON response: