Eda*_*lol 4 java android google-maps google-maps-markers google-maps-android-api-2
我正在尝试更改标记的颜色.
我有这个:
private void addMarker(GoogleMap map, double lat, double lon,
int title, int snippet) {
map.addMarker(new MarkerOptions().position(new LatLng(lat, lon))
.title(getString(title))
.snippet(getString(snippet)));
Run Code Online (Sandbox Code Playgroud)
然后这个添加一个标记:
addMarker(map, 40.748963847316034, -73.96807193756104,
R.string.title, R.string.snippet);
Run Code Online (Sandbox Code Playgroud)
我想改变标记的颜色,我认为它很容易,只需像这样实现:
private void addMarker(GoogleMap map, double lat, double lon,
int title, int snippet, int icon) {
map.addMarker(new MarkerOptions().position(new LatLng(lat, lon))
.title(getString(title))
.snippet(getString(snippet))
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.(getString(icon)));
Run Code Online (Sandbox Code Playgroud)
和:
addMarker(map, 40.748963847316034, -73.96807193756104,
R.string.title, R.string.snippet, HUE_AZURE);
Run Code Online (Sandbox Code Playgroud)
但我显然不能将"getString"与".icon"一起使用.
我怎样才能做到这一点?
另外,API 8+支持的改变颜色的方法是什么?我在支持API 8+时遇到了很多问题,如果这打破了某些东西会很糟糕......
这是一个循环,我在地图上设置不同颜色的标记,它对我很有用:
for (Task tempTask : TasksListAppObj.getInstance().tasksRepository.getTasksRepository())
{
LatLng latlng = new LatLng(tempTask.getLatitude(), tempTask.getLongtitude());
if (tempTask.getStatus().contentEquals(TasksListActivity.STATUS_WAITING))
{
newmarker = map.addMarker(new MarkerOptions().position(latlng).title(tempTask.getTitle()).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_for_map_blue)));
}
else if (tempTask.getStatus().contentEquals(TasksListActivity.STATUS_IN_PROGRESS))
{
newmarker = map.addMarker(new MarkerOptions().position(latlng).title(tempTask.getTitle()).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_for_map_bordo)));
}
else if (tempTask.getStatus().contentEquals(TasksListActivity.STATUS_ON_THE_WAY))
{
newmarker = map.addMarker(new MarkerOptions().position(latlng).title(tempTask.getTitle()).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_for_map_turkiz)));
}
else if (tempTask.getStatus().contentEquals(TasksListActivity.STATUS_COMPLETE))
{
newmarker = map.addMarker(new MarkerOptions().position(latlng).title(tempTask.getTitle()).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_for_map_orange)));
}
else if (tempTask.getStatus().contentEquals(TasksListActivity.STATUS_FAILED))
{
newmarker = map.addMarker(new MarkerOptions().position(latlng).title(tempTask.getTitle()).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_for_map_purpul)));
}
}
Run Code Online (Sandbox Code Playgroud)
看看它是否对你有所帮助.
if语句用于更改标记图标.
小智 5
以下代码片段为我提供了没有依赖关系的技巧:
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE);
myMap.addMarker(new MarkerOptions()
.position(point)
.icon(bitmapDescriptor)
.title(point.toString()));
Run Code Online (Sandbox Code Playgroud)
在这里找到它:http://android-er.blogspot.de/2013/01/change-marker-color-of-googlemaps-v2.html
归档时间: |
|
查看次数: |
9567 次 |
最近记录: |