Google Maps Android how do you display arrows indicating nearby markers outside boundaries?
Asked Answered
E

1

6

A pictures describes more than a thousand words, so I have created the below sketch using my poor Gimp skills.

enter image description here

The icon in the middle is the user's current location and the markers around is nearby places. The black square indicates what the user can see on the map with the current zoom level, however this only shows 2 places.

So my question is:

Is there any built-in way to display some kind of indicators in the outer screen area such that the user can see that there are nearby places just outside the visible area on the screen at the moment. It would be nice if these indicators could show markers not displayed within the square but within a given radius.

If no built-in way, what should I look into in order to solve this?

Eatmon answered 10/10, 2017 at 21:26 Comment(1)
Seems, there is no built-in way to do that. But if you know coordinates of markers you can implement it: just override MapView's onDraw (or add View over MapView) and draw arrows points to several nearest outside markers. And update them on onMapLoaded() method.Crepuscular
T
0

You can use a LatLngBounds.Builder; and SphericalUtil to do that. here is the example.

double radius = 1000; // 1km distance.
LatLngBounds.Builder builder = new LatLngBounds.Builder();
double distance = SphericalUtil.computeDistanceBetween(currentPosition, marker.getPosition());
if (distance < radius) {
    // include the marker within the 1km distance.
    builder.include(marker.getPosition()); 
}
googleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(builder.build(), 19));

don't forget to add the compile 'com.google.maps.android:android-maps-utils:0.5' to your build.gradle to use the SphericalUtil

Tuantuareg answered 10/10, 2017 at 22:58 Comment(3)
Thanks Jerrol. However as I read your code, it just calculates the boundaries to display all the places within the given radius on the screen. This is not what I want. I want to keep the zoom level and then show some kind of symbols (the double arrows) in the outer screen to indicate to the user that if he moves in that direction, or adjust the zoom level him self, then he will see the marker / place.Eatmon
OK, so may I know your current camera zoom level of the map?Tuantuareg
The zoom level is dynamically decided by the user. He can pinch in an out to adjust the zoom level. So maybe we should skip the radius and just say that all markers outside the boundaries of the screen should be indicated with the double arrow icon. Then I can always use your nice calculation using SphericalUtil to filter some of them out if they are too far away.Eatmon

© 2022 - 2024 — McMap. All rights reserved.