我想在谷歌地图上显示图像,但我不知道如何在 android 中做到这一点。和Panoramio一样 。到目前为止,我的 android 应用程序捕获带有纬度、经度的图像保存在 sqllite 数据库中。我想根据它们的纬度、经度在谷歌地图上填充这些图像。
问问题
3969 次
2 回答
1
首先你需要得到地图,像这样
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));;
}
检查谷歌开发者网站 https://developers.google.com/maps/documentation/android/marker?hl=pt-PT中的信息
于 2014-03-14T12:32:37.640 回答
0
您可以使用这样的东西来创建一个带有图像作为图标的标记:
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);
}
于 2014-03-14T12:33:49.643 回答