问题描述
朋友,
如何使用GPS和Wify在Mono中为邮政编码检测当前位置(适用于android).不需要额外的地址..
Hi Friends,
How to detect current location with Postal code in mono for android using GPS and Wify . no extra Address needed..
推荐答案
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();
字符串表达式="//GeocodeResponse/result/address_component [type = \" postal_code \]/long_name/text()";
InputSource inputSource =新的InputSource("https://maps.googleapis.com/maps/api/geocode/xml?latlng=37.775,-122.4183333&sensor=true");
字符串邮政编码=(String)xpath.evaluate(expression,inputSource,XPathConstants.STRING);
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);
这篇关于邮政编码的当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!