在Google地图中显示距离和附近标记的名称

时间:2018-08-10 14:20:19

标签: android google-maps google-maps-markers

我想创建文本气泡,以显示从该标记到设备位置的距离,以及标记的名称。这些是我预先设置的标记:

mMap.addMarker(new MarkerOptions().position(new LatLng(51.1691158, 4.4662486)).icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_marker)));

这是我想到的设计图: On the bottom of the activity, you should see textbubbles that you can scroll and click on

1 个答案:

答案 0 :(得分:1)

要显示文本气泡,可以使用同一Google Maps API中的InfoWindow

static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298);
Marker melbourne = mMap.addMarker(new MarkerOptions()
                      .position(MELBOURNE)
                      .title("Melbourne"));
melbourne.showInfoWindow();

要获取两个位置之间的差异,可以使用:

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);

代码示例参考为here

参考: 。 https://developer.android.com/reference/android/location/Location#distanceTo(android.location.Location)https://developers.google.com/maps/documentation/android-sdk/infowindows