How to get the coordinates of a point at a certain distance from my location?

Asked

Viewed 1,084 times

5

Speak guys, I’m making an app, and in an app Activity need from my location to "zoom" in the maps as the user slides a seekBar, as per the image.

Activity

I’ve been thinking about using the Bounds feature on the maps, where I can pass two longitudes and latitudes so that the maps create a border and zoom.

LatLngBounds bounds = new LatLngBounds.Builder()
                    .include(providerLocation)
                    .include(myLocation)
                    .build();
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, getWidthScreen()-0, getHeightScreen()-0, 190));

My problem is this, I’m not able to calculate from my point the latitude of an X1 point, an x2 point, which would be the reference points.

I appreciate all your help !!!

1 answer

6

If what you want is to calculate a Bounds having a radius (half diagonal) equal to that indicated by seekBar and that its location is in the center, do so.

//Calcula o ponto à distância 'raio' do 'centro*' na direção 45º(canto superior direito)
LatLng norhtEast = SphericalUtil.computeOffset(centro, raio, 45);

//Calcula o ponto à distância 'raio' do 'centro' na direção 225º(canto inferior esquerdo)
LatLng southWest = SphericalUtil.computeOffset(centro, raio, 225);

LatLngBounds bounds = new LatLngBounds(southWest,norhtEast);

Where:

center - Latlng of your position.
thunderbolt - Distance in metres from the centre to the upper right and lower left corners of the Bounds

  • I have to do some research on this Sphericautil, to see if that’s what it is. Well I did, but it would be better an exact calculation that performed the spacing from my center to the diagonal corner of the maps.

  • Cameraupdatefactory.newLatLngBounds() did not do this?

  • well, I’m using it to reset the camera, and zoom in, but first I have to pass the Bolts to him, and that’s what I’m locking on to, I have to calculate a Latlng from the left position and one from the right position, ai include in Bounds and after step as parameter in Cameraupdatefactory.newLatLngBounds().

  • What I’m asking is whether the CameraUpdateFactory.newLatLngBounds() with the Bound calculated the way I indicated it didn’t do it?

  • Yes, with Bound caculated, but with this calculation did not generate the required zoom.

  • Try using it like this CameraUpdateFactory.newLatLngBounds(bounds, 0);

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.