First look at the effect of the picture: (with the company near the International Trade Center point)
The above is a map, the following is the geographical list, and some only geographical list (QQ dynamic location), this is a very common function. It has a special name: POI perimeter search.
Realize:
This effect is actually very simple, but you need to read the map of the API, here using the gold map of the Android SDK,SDK configuration is not explained here, at the end of the text will put some links for learning.
Ideas:
1, using the map positioning function, get the user's current position
2, according to the location information obtained call POI search, get location list
3, ListView display Location list
4, the user drags the map, obtains the map center coordinates the position information, and executes the 2~3 step
Code:
Layout:
<linearlayout
xmlns:android= "http://schemas.android.com/apk/res/android"
android:layout_width= " Match_parent "
android:layout_height=" match_parent "
android:orientation=" vertical "
>
< Com.amap.api.maps2d.MapView
android:id= "@+id/map_local"
android:layout_width= "Match_parent"
android:layout_height= "0DP"
android:layout_weight= "2"/>
<listview
android:id= "@+id/map_ List "
android:layout_width=" match_parent "
android:layout_height=" 0DP "
android:layout_weight=" 3 "
android:divider= "@color/space"
android:dividerheight= "1DP"
android:scrollbars= "None"/>
</LinearLayout>
Activity:
public class New_localactivity extends activity implements Locationsource, Amaplocationlistener, Amap.oncamerachangel
Istener, Poisearch.onpoisearchlistener {@BindView (r.id.map_local) Mapview Mapview;
@BindView (r.id.map_list) ListView maplist;
public static final String Key_lat = "LAT";
public static final String key_lng = "LNG";
public static final String key_des = "DES";
Private Amaplocationclient mlocationclient;
Private Locationsource.onlocationchangedlistener Mlistener;
Private LATLNG latlng;
Private String City;
Private AMap AMap;
Private String Deeptype = "";//POI Search Type Private poisearch.query query;//POI query Condition class private Poisearch poisearch; Private Poiresult Poiresult; The results returned by POI private Poioverlay poioverlay;//poi layer Private list<poiitem> poiitems;//POI data Private Poisearch_
Adapter adapter;
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_new__local);
Butterknife.bind (this);
Mapview.oncreate (savedinstancestate);
Init ();
private void init () {if (AMap = null) {AMap = Mapview.getmap ();
Amap.setoncamerachangelistener (this);
Setupmap (); Deeptype = "Catering"; here take catering as an example}//--------locate Start------private void Setupmap () {if (mlocationclient = =
NULL) {mlocationclient = new Amaplocationclient (Getapplicationcontext ());
Amaplocationclientoption mlocationoption = new Amaplocationclientoption ();
Set positioning monitoring Mlocationclient.setlocationlistener (this);
Set to high precision positioning mode mlocationoption.setoncelocation (TRUE);
Mlocationoption.setlocationmode (AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
Setting the positioning parameter mlocationclient.setlocationoption (mlocationoption);
Mlocationclient.startlocation ();
///Custom system positioning small blue dot mylocationstyle mylocationstyle = new Mylocationstyle (); Mylocationstyle.mylocationicon (BITMApdescriptorfactory. Fromresource (R.drawable.location_marker))//Set icon for small blue dots mylocationstyle.strokecolor (Color.B LACK)//Set the border color of the Circle Mylocationstyle.radiusfillcolor (Color.argb (100, 0, 0, 180));/Set the fill color of the circle Mylocationstyle.stroke
Width (1.0f);//Set rounded border thickness amap.setmylocationstyle (mylocationstyle); Amap.setlocationsource (this);/Set position listening amap.getuisettings (). Setmylocationbuttonenabled (true);//Set the default Positioning button to display AMap. Setmylocationenabled (TRUE);//set to True to display the positioning layer and trigger the positioning, false indicates that the hidden positioning layer does not trigger positioning, the default is false}/** * Start poi search * * protecte
d void Dosearchquery () {amap.setonmapclicklistener (null);//Clear out the map click event int currentpage = 0 for poi search; query = new Poisearch.query ("", Deeptype, city);//The first parameter represents the search string, the second parameter represents the POI search type, and the third parameter represents the POI search area (the empty string represents the whole country) query.setpage Size (20);/Set the maximum number of returns per page Poiitem Query.setpagenum (currentpage);/Set Check first page latlonpoint LP = new Latlonpoint (Latlng.lat
Itude, Latlng.longitude);
Poisearch = new Poisearch (this, query); PoisearCh.setonpoisearchlistener (this);
Poisearch.setbound (New Poisearch.searchbound (LP, 5000, True)); Set the search area to be the center of the LP Point, with a range of 2000 meters around it Poisearch.searchpoiasyn ();//Asynchronous Search} @Override public void onlocationchanged (AMAPL Ocation amaplocation) {if (Mlistener!= null && amaplocation!= null) {if (Amaplocation.geterrorcode)
= = 0) {//Show my location mlistener.onlocationchanged (amaplocation);
Set the first focus center LATLNG = new LATLNG (Amaplocation.getlatitude (), Amaplocation.getlongitude ());
Amap.animatecamera (Cameraupdatefactory.newlatlngzoom (LATLNG), 1000, NULL);
City = Amaplocation.getprovince ();
Dosearchquery ();
else {String Errtext = "position failed," + amaplocation.geterrorcode () + ":" + amaplocation.geterrorinfo ();
LOG.E ("Amaperr", Errtext);
@Override public void Activate (Onlocationchangedlistener listener) {Mlistener = listener;
Mlocationclient.startlocation ();
}@Override public void Deactivate () {mlistener = null;
if (mlocationclient!= null) {mlocationclient.stoplocation ();
Mlocationclient.ondestroy ();
} mlocationclient = null; @Override public void Oncamerachange (Cameraposition cameraposition) {} @Override public void Oncamerachange
Finish (cameraposition cameraposition) {latlng = Cameraposition.target;
Amap.clear ();
Amap.addmarker (New Markeroptions (). Position (LATLNG));
Dosearchquery (); @Override public void onpoisearched (poiresult result, int rcode) {if (Rcode = = 0) {if (Result!= null & amp;& result.getquery ()!= null) {//Search results for POI if (Result.getquery (). Equals (query)) {//is the same one poires
Ult = result; Poiitems = Poiresult.getpois ()//Get the Poiitem data for the first page, starting with the number 0 list<suggestioncity> suggestioncities = Poiresu
Lt. Getsearchsuggestioncitys (); if (poiitems!= null && poiitems.size () > 0) {adapter = new Poisearch_adapter (this, poiitems);
Maplist.setadapter (adapter);
Maplist.setonitemclicklistener (New Monitemclicklistener ());
} else {LOGGER.D ("no results");
}} else {LOGGER.E ("no results");
} else if (Rcode = =) {LOGGER.E ("error_network");
else if (Rcode = =) {LOGGER.E ("Error_key");
else {LOGGER.E ("Error_other:" + rcode);
@Override public void onpoiitemsearched (Poiitem poiitem, int i) {}//--------Locate end------@Override
protected void Onresume () {super.onresume ();
Mlocationclient.startlocation ();
} @Override protected void OnPause () {super.onpause ();
Mlocationclient.stoplocation ();
} @Override protected void OnDestroy () {Mlocationclient.ondestroy ();
Super.ondestroy (); Private class Monitemclicklistener implements Adapterview.onitemclicklistEner {@Override public void Onitemclick (adapterview<?> parent, view view, int position, long id) {in
Tent Intent = new intent ();
Intent.putextra (Key_lat, poiitems.get (position). Getlatlonpoint (). Getlatitude ());
Intent.putextra (KEY_LNG, poiitems.get (position). Getlatlonpoint (). Getlongitude ());
Intent.putextra (Key_des, poiitems.get (position). GetTitle ());
Setresult (RESULT_OK, intent);
Finish ();
}
}
The activity in the example is started by using the Startactivityforresult method, and the last click Position returns the selected location information.
Summary: The first time I am ready to achieve the above results, is also overwhelmed, because there is no more comprehensive understanding of the map API, and then read a lot of information, they have combined the function points of the map to achieve the design of the effect of the diagram.
The author of this article: He called himself Mr Zhang
This article address: http://blog.csdn.net/ys743276112/article/details/51519223
The above is the entire content of this article, very grateful to the author of the sharing, I hope that the learning of everyone help, we common progress.