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)
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
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)
Country | India |
---|---|
Latitude | 17.361431 |
Longitude | 78.474533 |
DMS Lat | 17° 21' 41.1516'' N |
DMS Long | 78° 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
Post a Comment