我正在使用 java 开发一个包含映射功能的 android 项目。我的问题是如何添加具有不同颜色(红色,蓝色)的多个标记(两个不同的标记)。
我使用了谷歌地图 api。任何帮助表示赞赏。
我正在使用 java 开发一个包含映射功能的 android 项目。我的问题是如何添加具有不同颜色(红色,蓝色)的多个标记(两个不同的标记)。
我使用了谷歌地图 api。任何帮助表示赞赏。
试试这种方式:
private static final LatLng BRISBANE = new LatLng(-27.47093, 153.0235); private static final LatLng MELBOURNE = new LatLng(-37.81319, 144.96298); private static final LatLng SYDNEY = new LatLng(-33.87365, 151.20689); private static final LatLng ADELAIDE = new LatLng(-34.92873, 138.59995); private static final LatLng PERTH = new LatLng(-31.952854, 115.857342); private void addMarkersToMap() { // Uses a colored icon. mBrisbane = mMap.addMarker(new MarkerOptions() .position(BRISBANE) .title("Brisbane") .snippet("Population: 2,074,200") .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))); // Uses a custom icon. mSydney = mMap.addMarker(new MarkerOptions() .position(SYDNEY) .title("Sydney") .snippet("Population: 4,627,300") .icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow))); // Creates a draggable marker. Long press to drag. mMelbourne = mMap.addMarker(new MarkerOptions() .position(MELBOURNE) .title("Melbourne") .snippet("Population: 4,137,400") .draggable(true)); // A few more markers for good measure. mPerth = mMap.addMarker(new MarkerOptions() .position(PERTH) .title("Perth") .snippet("Population: 1,738,800")); mAdelaide = mMap.addMarker(new MarkerOptions() .position(ADELAIDE) .title("Adelaide") .snippet("Population: 1,213,000")); // Creates a marker rainbow demonstrating how to create default marker icons of different // hues (colors). int numMarkersInRainbow = 12; for (int i = 0; i < numMarkersInRainbow; i++) { mMap.addMarker(new MarkerOptions() .position(new LatLng( -30 + 10 * Math.sin(i * Math.PI / (numMarkersInRainbow - 1)), 135 - 10 * Math.cos(i * Math.PI / (numMarkersInRainbow - 1)))) .title("Marker " + i) .icon(BitmapDescriptorFactory.defaultMarker(i * 360 / numMarkersInRainbow))); } }
1.始终参考Android官方文档;
关于 Google Maps API v2 上的标记的所有信息(单击此处)
2.你可以在那里得到你想知道的。
3.你可以在这里得到它的示例代码点击
4.欲了解更多信息,请与我联系,然后让您了解。
[更新]
5.如果你想在谷歌地图上用触摸和拖动事件绘制多段线,请看这部电影和教程,如下所示;
5-1。请参阅*YouTube 电影。
5-2。请看*电影引用的源代码。