Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Friends,

How to detect current location with Postal code in mono for android using GPS and Wify . no extra Address needed..
Posted

1 solution

SQL
You can do it with Google's Geocoding API. What you're actually looking for is reverse-geocoding, but it supports that too. You can have it return XML and then parse it for the postal code (a.k.a zipcode). Should be quite simple actually.

To use the API, simply access it by HTTP with the correct latitude and longitude:

https://maps.googleapis.com/maps/api/geocode/xml?latlng=37.775,-122.4183333&sensor=true

Then parse the XML using XPath, or your favorite XML parser (or just use JSON):

XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "//GeocodeResponse/result/address_component[type=\"postal_code\"]/long_name/text()";
InputSource inputSource = new InputSource("https://maps.googleapis.com/maps/api/geocode/xml?latlng=37.775,-122.4183333&sensor=true");
String zipcode = (String) xpath.evaluate(expression, inputSource, XPathConstants.STRING);
 
Share this answer
 
Comments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900