如何使用Android google mapV2获取地图的经纬度

时间:2013-01-04 07:19:58

标签: android google-maps google-maps-android-api-2

我正在使用Android google maps V2查找 mapView右上角的纬度和经度值。我在同一个问题上发布了类似的问题,但没有用。

我为此编写了代码,但获得了零值。

请检查我的代码:

MapView mapView = ((SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map)).getMap();

    LatLngBounds bounds = mapView.getProjection().getVisibleRegion().latLngBounds;
            LatLng topright = bounds.northeast;
            double toprgt_latitude = topright.latitude;

            Log.d("top lat", "" + toprgt_latitude);//getting zero values.

2 个答案:

答案 0 :(得分:1)

显示地图后使用mapView.getProjection()。getVisibleRegion()。latLngBounds.northeast。

LatLng corner;

mapView.setOnCameraChangeListener(new OnCameraChangeListener() {
  @Override
  public void onCameraChange(CameraPosition position) {
    corner = mapView.getProjection().getVisibleRegion().latLngBounds.northeast;    
  }
}

答案 1 :(得分:0)

LatLng currentposition = new LatLng(location.getLatitude(), location.getLongitude());
sys.out.println(""+location.getLatitude()""+location.getLongitude());