公司有个需求就是要随着屏幕的改变而载入附近的商户信息.
那么高德地图获取当前屏幕中心点的经纬度呢?
核心方法:aMap.setOnCameraChangeListener(this);
实现接口:
@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地图中介绍怎样显示一个基本地图 */ 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 } } </span>
结果展示
时间: 2024-10-04 20:11:36