![](/img/trans.png)
[英]Draw custom map tile images (.pngs) on top of Google Map - Android
[英]Add images on google map in android
我想在Google地图上显示图像,但我不知道如何在android中进行操作。 就像Panoramio .i到目前为止一样,我的android应用捕获了经度和纬度图像,并保存在sqllite数据库中。
首先,您需要获取地图,像这样
private GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
然后您可以创建一个循环,在其中可以向地图添加标记
for (all the items you want to add) {
mMap.addMarker(new MarkerOptions()
.position(LatLng(coordinates))
.icon(BitmapDescriptorFactory.from where you have it));;
}
在Google开发人员网站中查看信息https://developers.google.com/maps/documentation/android/marker?hl=pt-PT
您可以使用类似这样的方法来创建一个带有图像作为图标的标记:
private MarkerOptions createMarker(LatLng position, String title, String snippet, String image_path) {
// Standard marker icon in case image is not found
BitmapDescriptor icon = BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_RED);
if (!image_path.isEmpty()) {
File iconfile = new File(image_path);
if (iconfile.exists()) {
BitmapDescriptor loaded_icon = BitmapDescriptorFactory
.fromPath(image_path);
if (loaded_icon != null) {
icon = loaded_icon;
} else {
Log.e(TAG, "loaded_icon was null");
}
} else {
Log.e(TAG, "iconfile did not exist: "
+ image_path);
}
} else {
Log.e(TAG, "iconpath was empty: "
+ image_path);
}
return new MarkerOptions().position(position)
.title(title)
.snippet(snippet).icon(icon);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.