One of the company's needs is to load nearby merchant information as the screen changes.
So the map gets the latitude and longitude of the center point of the current screen?
Core method: Amap.setoncamerachangelistener (this);
Implementing the interface:
@Override
public void Oncamerachange (cameraposition position) {
LATLNG target = Position.target;
System.out.println (target.latitude + "jinjin------" + target.longitude);
}
<span style= "FONT-SIZE:18PX;" >package Com.amap.map2d.demo.basic; Import Android.app.activity;import Android.os.bundle;import Android.util.displaymetrics;import Com.amap.api.location.core.geopoint;import Com.amap.api.maps2d.amap;import Com.amap.api.maps2d.amap.oncamerachangelistener;import Com.amap.api.maps2d.mapview;import Com.amap.api.maps2d.model.cameraposition;import Com.amap.api.maps2d.model.latlng;import Com.amap.map2d.demo.R; /** * AMapV1 map describes how to display a basic map */public class Basicmapactivity extends Activity implements Oncamerachangelistener {private M Apview mapview;private AMap AMap; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.basicmap_activity); Mapview = (Mapview) Findviewbyid (R.ID.MAP); Mapview.oncreate (savedinstancestate);//This method must override Init (); Amap.setoncamerachangelistener (this);} /** * Initialize AMap object */private void init () {if (AMap = = null) {AMap = Mapview.getmap ();}} /** * method must be rewritten */@Overrideprotected void OnresumE () {super.onresume (); Mapview.onresume ();} /** * method must be rewritten */@Overrideprotected void OnPause () {super.onpause (); Mapview.onpause ();} /** * method must be rewritten */@Overrideprotected void onsaveinstancestate (Bundle outstate) {super.onsaveinstancestate (outstate); Mapview.onsaveinstancestate (outstate);} /** * method must be rewritten */@Overrideprotected void OnDestroy () {Super.ondestroy (); Mapview.ondestroy ();} @Overridepublic void Oncamerachange (cameraposition position) {latlng target = Position.target; System.out.println (target.latitude + "jinjin------" + target.longitude);} @Overridepublic void Oncamerachangefinish (cameraposition position) {//TODO auto-generated method stub}}</span>
Results show
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Gold map gets the latitude and longitude of the center point of the current screen