Skip to main content

Google Map API alternative for your GPS Tracking website reverse geocoding

Google Map API for reverse Geo-coding of Address information is not free now. You have some limitations for daily usage. being in GPS tracking world, we will need Reverse Geo-coding for all the vehicles we track.

In this Blog i will discuss some alternatives to Google maps for reverse Geo-coding.

ESRI REST API:


ESRI has a rest api using which you can reverse Geo-coding your Latitude and Longitude into an Address. The REST url returns a Json string with required Address information.

For Example i have below information of CharMinar area (an Historical Monument in Hyderbad,India)

CountryIndia
Latitude17.361431
Longitude78.474533
DMS Lat17° 21' 41.1516'' N
DMS Long78° 28' 28.3188'' E

The REST API to get reverse geo coded address

http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?location=78.474533%2C17.361431&langCode=fr&outSR=&forStorage=false&f=pjson


The REST response in json as below


{
 "address": {
  "Match_addr": "Kamla Maternity Nursing Home and Ultrasound Centre",
  "LongLabel": "Kamla Maternity Nursing Home and Ultrasound Centre, Charminar Chowk, Chandulal Baradari, Hyderabad, Telangana, 500002, IND",
  "ShortLabel": "Kamla Maternity Nursing Home and Ultrasound Centre",
  "Addr_type": "POI",
  "Type": "Medical Clinic",
  "PlaceName": "Kamla Maternity Nursing Home and Ultrasound Centre",
  "AddNum": "",
  "Address": "Charminar Chowk",
  "Block": "",
  "Sector": "",
  "Neighborhood": "",
  "District": "Chandulal Baradari",
  "City": "Hyderabad",
  "MetroArea": "Greater Hyderabad",
  "Subregion": "Hyderabad",
  "Region": "Telangana",
  "Territory": "",
  "Postal": "500002",
  "PostalExt": "",
  "CountryCode": "IND"
 },
 "location": {
  "x": 78.474430000000041,
  "y": 17.361410000000035,
  "spatialReference": {
   "wkid": 4326,
   "latestWkid": 4326
  }
 }
}

Summary: using any json de-serializer , you can grab the required information to store the same to your database for later use. the below code snippet is an example from c# code.


C# code------------------------


// create a function to GET the json string by consuming the ESRI Rest


    string GET(string url)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        try
        {
            WebResponse response = request.GetResponse();
            using (Stream responseStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream, System.Text.Encoding.UTF8);
                return reader.ReadToEnd();
            }
        }
        catch (WebException ex)
        {
            WebResponse errorResponse = ex.Response;
            using (Stream responseStream = errorResponse.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream, System.Text.Encoding.GetEncoding("utf-8"));
                String errorText = reader.ReadToEnd();
                // log errorText
            }
            throw;
        }
    }


// Call above function as below

String ucode = GET("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseGeocode?location=" + LONGITUDE + "%2C" + LATITUDE + "langCode=fr&outSR=&forStorage=false&f=pjson");
// de-serialization  of json, i have used Newtonsoft json.net for the purpose

var json = ucode;

dynamic results = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(json);
                    
String id = results.address.LongLabel;  // i need only longlabel, you can grab any 




I will post another way of reverse-geocoding in my next blog..feel free to ask any questions related to the above at sree@itoolz.in

 

Comments

Popular posts from this blog

Reverse geo-coding using Open Street Maps - a best alternative for Google Maps

In my previous post, i have explained how to consume ESRI Rest API for reverse geocoding. In this Article i will explain how to use " nominatim " for reverse geo-coding. Nominatim (from the Latin, 'by name') is a tool to search OSM data by name and address and to generate synthetic addresses of OSM points (reverse geocoding). It can be found at nominatim.openstreetmap.org. Nominatim is also used as one of the sources for the search box on the OpenStreetMap home page. Several companies provide hosted instances of Nominatim that you can query via an API, Just like in my earlier blog, i took Charminar coordinates for testing! ReverseGeocoding- xml URL https://nominatim.openstreetmap.org/reverse?format=xml&lat=17.3616&lon=78.4747&zoom=18&addressdetails=1 --XML RESPONSE FROM NOMINATIM SERVER---------- <reversegeocode timestamp="Mon, 10 Dec 18 09:29:01 +0000" attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://ww