The search address function is based on the ability to get location through the Baidu map API
Get location details by Baidu Map Locator: http://www.cnblogs.com/zzw1994/p/5008134.html
1 PackageCom.zzw.baidumappoint;2 3 Importcom.baidu.location.BDLocation;4 ImportCom.baidu.location.BDLocationListener;5 Importcom.baidu.location.LocationClient;6 Importcom.baidu.location.LocationClientOption;7 ImportCom.baidu.mapapi.SDKInitializer;8 ImportCom.baidu.mapapi.map.BaiduMap;9 Importcom.baidu.mapapi.map.MapStatusUpdate;Ten Importcom.baidu.mapapi.map.MapStatusUpdateFactory; One ImportCom.baidu.mapapi.map.MapView; A ImportCom.baidu.mapapi.map.MyLocationData; - ImportCom.baidu.mapapi.model.LatLng; - Importcom.baidu.mapapi.search.geocode.GeoCodeOption; the ImportCom.baidu.mapapi.search.geocode.GeoCodeResult; - ImportCom.baidu.mapapi.search.geocode.GeoCoder; - ImportCom.baidu.mapapi.search.geocode.OnGetGeoCoderResultListener; - ImportCom.baidu.mapapi.search.geocode.ReverseGeoCodeResult; + - Importandroid.app.Activity; + ImportAndroid.os.Bundle; A ImportAndroid.view.View; at ImportAndroid.view.View.OnClickListener; - ImportAndroid.widget.EditText; - ImportAndroid.widget.Toast; - - Public classMainactivityextendsActivity { - in Privatelocationclient mlocationclient; - PrivateBaidumap Mbaidumap; to PrivateGeoCoder Mgeocoder; + - @Override the protected voidonCreate (Bundle savedinstancestate) { * Super. OnCreate (savedinstancestate); $Sdkinitializer.initialize (Getapplicationcontext ());//The effect of making the program not crashPanax Notoginseng Setcontentview (r.layout.activity_main); - the FinalEditText City_edit =(EditText) Findviewbyid (r.id.city); + FinalEditText Addr_edit =(EditText) Findviewbyid (R.ID.ADDR); A //Get Locationclient theMlocationclient =NewLocationclient ( This); + - //Get Geocoder $Mgeocoder =geocoder.newinstance (); $Mgeocoder.setongetgeocoderesultlistener (NewOngetgeocoderresultlistener () { - - @Override the Public voidOngetreversegeocoderesult (reversegeocoderesult result) { - Wuyi } the - @Override Wu Public voidOngetgeocoderesult (geocoderesult result) { - Try{ AboutLATLNG LL =result.getlocation (); $ //just completed the positioning -Mylocationdata Locdata =NewMylocationdata.builder (). Latitude (ll.latitude). Longitude (ll.longitude) - . Build (); - A //set the position of the icon on the map + Mbaidumap.setmylocationdata (locdata); the - //start moving the location of the Baidu map to the central location $Mapstatusupdate U = mapstatusupdatefactory.newlatlngzoom (ll, 16.0f); the mbaidumap.animatemapstatus (u); the}Catch(Exception e) { theToast.maketext (Getapplicationcontext (), "Please check address", 0). Show (); the } - } in }); the theFindviewbyid (R.id.go). Setonclicklistener (NewOnclicklistener () { About the @Override the Public voidOnClick (View v) { the Try { +String city = city_edit.gettext () + ""; -String addr = Addr_edit.gettext () + ""; theCity_edit.settext ("");BayiAddr_edit.settext (""); theMgeocoder.geocode (Newgeocodeoption (). City (City.trim ()). Address (Addr.trim ())); the}Catch(Exception e) { - - } the the } the }); thelocationclientoption option =Newlocationclientoption (); -Option.setcoortype ("Bd09ll"); the mlocationclient.setlocoption (option); the the //Get Baidumap94Mapview Mapview =(Mapview) Findviewbyid (R.id.mapview); theMbaidumap =Mapview.getmap (); the the //small icon showing the current position98Mbaidumap.setmylocationenabled (true); About -Mylocationlistener Mlistener =NewMylocationlistener ();101 Mlocationclient.registerlocationlistener (mlistener);102 Mlocationclient.start ();103 }104 the @Override106 protected voidOnDestroy () {107 mlocationclient.stop ();108 Super. OnDestroy ();109 } the 111 Private classMylocationlistenerImplementsBdlocationlistener { the 113 @Override the Public voidonreceivelocation (bdlocation location) { the the //just completed the positioning117Mylocationdata Locdata =NewMylocationdata.builder (). Latitude (Location.getlatitude ())118 . Longitude (Location.getlongitude ()). build ();119 - //set the position of the icon on the map121 Mbaidumap.setmylocationdata (locdata);122 123 //start moving the location of the Baidu map to the central location124LATLNG LL =Newlatlng (Location.getlatitude (), Location.getlongitude ()); theMapstatusupdate U = mapstatusupdatefactory.newlatlngzoom (ll, 16.0f);126 mbaidumap.animatemapstatus (u);127 } - 129 } the 131}
Baidu Map API to achieve the search address-third party open source-Baidu map (three)