Over a million developers have joined DZone.

How to Add Geocoding Lookup to Your App in 5 Minutes

Use Appery.io Server Code to add geocoding functionality to your Android App.

· Mobile Zone

Visually compose APIs with easy-to-use tooling. Learn how IBM API Connect provides near-universal access to data and services both on-premises and in the cloud, brought to you in partnership with IBM.

Let’s say you are building a mobile app where you enter an address and need to get back the location as latitude/longitude information. To do this in Appery.io Server Code is super simple. Here is a Server Code script that looks up an address and returns the latitude/longitude information for the location using the Google Geocoding API:

var address = request.get("address");
var url = "https://maps.googleapis.com/maps/api/geocode/json"; 

var XHRResponse = XHR2.send("GET", url, {
   "parameters": {
      "address": address,
      "key": "AIzaSyAFQBtqmC.........."

var responseInJson = JSON.parse(XHRResponse.body);

Apperyio.response.success(responseInJson.results[0].geometry.location, "application/json");

When you run this script, the result looks like this (using Boston as input):

   "lng": -71.0588801,
   "lat": 42.3600825

The script has an API which you can invoke from your app:


Here is an example invoking the script directly from the browser:

Screen Shot 2016-04-13 at 12.34.54 PM

Invoking the Server Code Script

With geolocation logic on the server, you can change the implementation. For example you can use a different API without making any changes to the app and impacting the users.

The Mobile Zone is brought to you in partnership with Strongloop and IBM.  Visually compose APIs with easy-to-use tooling. Learn how IBM API Connect provides near-universal access to data and services both on-premises and in the cloud.


Published at DZone with permission of Max Katz, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}