Working with the Google Maps JSON file


Nov. 12

7.02 K


This is a continuation from our previous post on working with Google Maps API. This post expands on the JSON file returned by the Google Maps API. To understand the conventions of the JSON file let me refer you to conventions used in JSON in this link here. Note that we were retrieving the latitude and longitude of a location. After understanding this post you can modify the code to get other kinds of data from the file. Now moving on we now have a static web address pointing to a JSON resource that is stored in the string readadress. We read the same address into a JSON object as shown below: [sourcecode language=”java”] JSONObject jsonObject = new JSONObject(readadress).getJSONArray(“results”).getJSONObject(0).getJSONObject(“geometry”).getJSONObject(“location”); [/sourcecode] Now you might be wondering here :”Ok we are passing the location of the JSON file through the string readadress to the JSONObject constructor but what the hell are the other things going on about?”. To properly understand what each breadcrumb is accessing I will colour code each breadcrumb and you can match the colour to a corresponding resource in the JSON file below it.

Track the breadcrumbs in the thumbnail of the JSON file below.

Let me show you the contents of the JSON file that is returned for our “Taj Mahal” query now:The JSON file returned for the Taj Mahal query If you trace it properly you see that in the end you have initialized a JSONObject with 2 attributes that are copied from the location object. In other words you finally have the coordinates which you then copy into the latlong string (that will be returned by the main function SendLatLong) with the following code. [sourcecode language=”java”] String eventLat = jsonObject.getString(“lat”); String eventLng = jsonObject.getString(“lng”); latlong = eventLat + “,” + eventLng; [/sourcecode] Alternatively you can modify the code to fetch different details like PIN codes and state and country. Just trace your breadcrumb to the proper object in the JSON file and copy it to proper objects. Now that you have learned this go and show people some awesomeness, tell us if you need any help.We hope that this post will help you to build crazy & amazing mobile application.


Lets Nurture
Posted by Lets Nurture

Blog A directory of wonderful things

Drive to Your Destiny: Google Maps Updated for Android Wear

Since the release of Android wear, many are expecting to get the update of Google Maps as it was not working properly. There was a problem with the navigation commands …

Using Google Maps API In Android App Development: Getting Geo Co-Ordinates

So now you will learn how to get Geo-coordinates from strings using Google’s maps API. Since you guys are kind of a newbie you have to learn a little something …

Android App Development Team Celebrating 1K Downloads of ‘Navratri Dhamaal App’

LetsNurture android team achieves another feather in their cap as Navratri Dhamaal has reached over a thousand downloads in just 2 weeks of its release. And why not? An awesome …

What India and the UK searched on internet the most?

With more and more people using GPS navigation on their mobile devices, people are utilizing their devices for local searches; India has started using the internet on the 3G networks …


Have an !dea or need help with your current business?

We use cookies to give you tailored experiences on our website.