Obtain GPS information via mobile phone, then use GPS latitude and longitude to query the corresponding geographical location information.
1, the use of Android with the implementation of the API, after testing basically no results. Reserved for reference. The key code is as follows:
Geocoder geocoder=new Geocoder (gotomylocationactivity.this); Geocoder Geocoder = new Geocoder (this, Locale.china); try { //thread.sleep (+); Places = Geocoder.getfromlocation (latitude, longitude, 5); Thread.Sleep (+); Toast.maketext (Gotomylocationactivity.this, places.size () + "", Toast.length_long). Show (); System.out.println (places.size () + ""); } catch (Exception e) { e.printstacktrace (); }
String placename = ""; if (places! = null && places.size () > 0) { //placename= (Address) places.get (0)). getlocality (); The information will be specific to a street //Where Getaddressline (0) represents the state, Getaddressline (1) is accurate to a certain area, getaddressline (2) means precise to the specific street placename = (address) places.get (0)). Getaddressline (0) + "," + System.getproperty ("Line.separator") + (address) Places.get (0)). Getaddressline (1) + "," + (Address) places.get (0)). Getaddressline (2); Toast.maketext (Gotomylocationactivity.this, placename, Toast.length_long). Show (); else{ Toast.maketext (gotomylocationactivity.this, "Cannot get geographic information", Toast.length_long). Show ();
2, using the Baidu Map API implementation
Key code:
GPS coded into geolocation//Initialize search module, register event Monitor//Turn GPS signal into Baidu map coordinates jwd JWD = Gpstobaidu.getdata (longitude+ "", latitude+ "");//latlng Ptcenter = new Latlng (latitude, longitude);p tcenter = new Latlng (double.parsedouble (Jwd.gety ()), double.parsedouble ( Jwd.getx ()));
Msearch.reversegeocode (New Reversegeocodeoption (). Location (Ptcenter)); Msearch.setongetgeocoderesultlistener (new Ongetgeocoderresultlistener () {@Overridepublic void Ongetreversegeocoderesult (reversegeocoderesult result) {if ( result = = Null| | Result.error! = SearchResult.ERRORNO.NO_ERROR) {toast.maketext (gotomylocationactivity.this, "Sorry, the results could not be found", Toast.length_long). Show (); return;} Toast.maketext (Gotomylocationactivity.this,result.getaddress (), Toast.length_long). Show (); mAddr = Result.getaddress ();
3, using the Web API implementation
Key code:
/** * * @param latitude latitude * @param longitude Longitude * @return returnvalue return address related information */public static returnvalue geocoding (S Tring latitude, String longitude) {//string L = "http://api.map.baidu.com/geocoder/v2/?ak= E4805d16520de693a3fe707cdc962045&location=39.983424,116.322987&output=json&pois=1 ";//ak mean the Key.you should apply it from Baidu. String key = "Xxxxxxxxxxxxxxxxx"; String url = "http://api.map.baidu.com/geocoder/v2/" + "ak=" +key+ "&location=" +latitude+ "," +longitude+ "& Output=json&pois=1 "; ReturnValue RV = HttpRequest (URL, "GET"); if (NULL==RV) return Null;return RV;}
demo:http://download.csdn.net/detail/u014600432/8184399
Based on the Baidu map of the Android location access