Issue
I'd like to create textbubbles that show the distance from that marker to the devices location, plus the name given to the marker. These are markers I set in advance:
mMap.addMarker(new MarkerOptions().position(new LatLng(51.1691158, 4.4662486)).icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_marker)));
This is an image of the design I had in mind: On the bottom of the activity, you should see textbubbles that you can scroll and click on
Solution
To display textbubbles, you can use InfoWindow from the same Google Maps API.
static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298);
Marker melbourne = mMap.addMarker(new MarkerOptions()
.position(MELBOURNE)
.title("Melbourne"));
melbourne.showInfoWindow();
and to get the difference between two locations, you can use:
Location loc1 = new Location(""); loc1.setLatitude(lat1); loc1.setLongitude(lon1); Location loc2 = new Location(""); loc2.setLatitude(lat2); loc2.setLongitude(lon2); float distanceInMeters = loc1.distanceTo(loc2);
The code example is from here.
Reference:
- https://developer.android.com/reference/android/location/Location#distanceTo(android.location.Location)
- https://developers.google.com/maps/documentation/android-sdk/infowindows
Answered By - DavidBarbaran
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)