在 Google 地图中显示附近标记的距离和名称
Show distance and name of nearby markers in Google Maps
我想创建文本气泡来显示从该标记到设备位置的距离,以及为标记指定的名称。这些是我预先设置的标记:
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
要显示文本气泡,您可以使用来自同一个 Google 地图的 InfoWindow API。
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
我想创建文本气泡来显示从该标记到设备位置的距离,以及为标记指定的名称。这些是我预先设置的标记:
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
要显示文本气泡,您可以使用来自同一个 Google 地图的 InfoWindow API。
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