项目刚好有个需求就是要随着屏幕的改变而加载附近的商户信息,那么高德地图获取当前屏幕中心点的经纬度呢?
其实核心方法就是:aMap.setOnCameraChangeListener(this),下面是实现代码
实现接口:
@Override public void onCameraChange(CameraPosition position) { LatLng target = position.target; System.out.println(target.latitude + "jinjin------" + target.longitude); }
/** * AMapV1地图中介绍如何显示一个基本地图 */ public class BasicMapActivity extends Activity implements OnCameraChangeListener { private MapView mapView; private AMap aMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.basicmap_activity); mapView = (MapView) findViewById(R.id.map); mapView.onCreate(savedInstanceState);// 此方法必须重写 init(); aMap.setOnCameraChangeListener(this); } /** * 初始化AMap对象 */ private void init() { if (aMap == null) { aMap = mapView.getMap(); } } /** * 方法必须重写 */ @Override protected void onResume() { super.onResume(); mapView.onResume(); } /** * 方法必须重写 */ @Override protected void onPause() { super.onPause(); mapView.onPause(); } /** * 方法必须重写 */ @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mapView.onSaveInstanceState(outState); } /** * 方法必须重写 */ @Override protected void onDestroy() { super.onDestroy(); mapView.onDestroy(); } @Override public void onCameraChange(CameraPosition position) { LatLng target = position.target; System.out.println(target.latitude + "jinjin------" + target.longitude); } @Override public void onCameraChangeFinish(CameraPosition position) { // TODO Auto-generated method stub } }