Click here to Skip to main content
11,715,160 members (61,613 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Mono Android For
Hi Friends,

How to detect current location with Postal code in mono for android using GPS and Wify . no extra Address needed..
Posted 17-Oct-12 23:54pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);
  Permalink  
Comments

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 495
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 775
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320


Advertise | Privacy | Mobile
Web04 | 2.8.150901.1 | Last Updated 18 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100