How to get Latitude/Longitude span in Google Map V2 for Android

前端 未结 4 1129
旧时难觅i
旧时难觅i 2020-12-08 22:22

I have a task for move my app to Google Maps Android APIs V2. Now, I need to get Latitude/Longitude span. I used MapView.getLatitudeSpan() and MapView.get

4条回答
  •  不知归路
    2020-12-08 23:21

    This way works for me:

    CameraPosition camPos2 = mapa.getCameraPosition();
    LatLng pos = camPos2.target;
    Toast.makeText(MainActivity.this,"Lat: " + pos.latitude + " - Lng: " +pos.longitude,  Toast.LENGTH_LONG).show();
    


    Oops, i misunderstood the question, i mean i did not saw "span" word. According the API the correct would be:

    First get the bounds:

    LatLngBounds bounds = gMap.getProjection().getVisibleRegion().latLngBounds;
    

    And then ask if any point is in bounds:

    LatLng point = new LatLng (latitude, longitude);
    if(bounds.contains(point)){
        //do something
    }
    

提交回复
热议问题