如何在android中显示多个静态位置?
How to display multiple static location in android?
我正在尝试在地图中与用户当前位置不同的位置显示标记。
现在我给了 两个静态值
1.) LatLng one = new LatLng(12.9010, 80.2279);
2.) LatLng two = new LatLng(12.9229, 80.1275);
但它没有在地图中显示标记,我得到的控制台输出具有 lat long 值 0,0.
这是我使用静态值在地图中获取标记位置的代码。
private void addmap() {
LatLng one = new LatLng(12.9010, 80.2279);
LatLng two = new LatLng(12.9229, 80.1275);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
//add them to builder
builder.include(one);
builder.include(two);
LatLngBounds bounds = builder.build();
//get width and height to current display screen
int width = getResources().getDisplayMetrics().widthPixels;
int height = getResources().getDisplayMetrics().heightPixels;
// 20% padding
int padding = (int) (width * 0.20);
//set latlong bounds
Mmap.setLatLngBoundsForCameraTarget(bounds);
//move camera to fill the bound to screen
Mmap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding));
//set zoom to level to current so that you won't be able to zoom out viz.
move outside bounds
// Mmap.setMinZoomPreference(mMap.getCameraPosition().zoom);
}
你可以把经纬度放在一个列表中,然后循环设置多个标记
这是示例
for (int i = 0; i < list.size(); i++) {
Marker marker;
marker = gMap.addMarker(new MarkerOptions().position(new LatLng(list.getLat(), list.getLng()))
.icon(BitmapDescriptorFactory.fromResource(R.mipmap.location_other))
.flat(true));
}
我正在尝试在地图中与用户当前位置不同的位置显示标记。 现在我给了 两个静态值
1.) LatLng one = new LatLng(12.9010, 80.2279);
2.) LatLng two = new LatLng(12.9229, 80.1275);
但它没有在地图中显示标记,我得到的控制台输出具有 lat long 值 0,0.
这是我使用静态值在地图中获取标记位置的代码。
private void addmap() {
LatLng one = new LatLng(12.9010, 80.2279);
LatLng two = new LatLng(12.9229, 80.1275);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
//add them to builder
builder.include(one);
builder.include(two);
LatLngBounds bounds = builder.build();
//get width and height to current display screen
int width = getResources().getDisplayMetrics().widthPixels;
int height = getResources().getDisplayMetrics().heightPixels;
// 20% padding
int padding = (int) (width * 0.20);
//set latlong bounds
Mmap.setLatLngBoundsForCameraTarget(bounds);
//move camera to fill the bound to screen
Mmap.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding));
//set zoom to level to current so that you won't be able to zoom out viz.
move outside bounds
// Mmap.setMinZoomPreference(mMap.getCameraPosition().zoom);
}
你可以把经纬度放在一个列表中,然后循环设置多个标记
这是示例
for (int i = 0; i < list.size(); i++) {
Marker marker;
marker = gMap.addMarker(new MarkerOptions().position(new LatLng(list.getLat(), list.getLng()))
.icon(BitmapDescriptorFactory.fromResource(R.mipmap.location_other))
.flat(true));
}