英文:
Issue related to display of markers on Google Maps
问题
这是我的代码,用于在Google地图上显示标记,其颜色由自定义函数analyzeSampleDataToMarkerColor()
决定,该函数在云中存储的数据中执行。标记一开始不会出现,但在随后的刷新后就可以正常工作。有什么原因吗?我应该在赋值之前分配变量marker
吗?或者应该在UI线程中实现该函数?
for (int i = 0; i < stations.size(); i++) {
LatLng pos = new LatLng(stations.get(i).getLatitude(), stations.get(i).getLongitude());
MarkerOptions markerOptions = new MarkerOptions()
.position(pos)
.icon(BitmapDescriptorFactory.defaultMarker(analyzeSampleDataToMarkerColor(stations.get(i))));
Marker marker = mMap.addMarker(markerOptions); // 在此赋值之前是否需要分配内存给 marker 变量?
}
英文:
This is my code to display markers, of varying colors dictated by custom function analyzeSampleDataToMarkerColor()
, on the google maps from a thread as the data resides in the cloud. The markers don't appear at first but works after subsequent refresh. Any reason? Should I allocate variable marker
before the assignment? Or should the function be implemented in the UI thread ?
for (int i = 0; i < stations.size(); i++) {
LatLng pos = new LatLng(stations.get(i).getLatitude(), stations.get(i).getLongitude());
MarkerOptions markerOptions = new MarkerOptions()
.position(pos)
.icon(BitmapDescriptorFactory.defaultMarker(analyzeSampleDataToMarkerColor(stations.get(i))));
Marker marker = mMap.addMarker(markerOptions); // memory allotment of marker require before this assignment?
}
答案1
得分: 1
在循环中调用showInfoWindow()
以显示标记,方法如下:
Marker marker = mMap.addMarker(markerOptions);
marker.showInfoWindow();
英文:
Call showInfoWindow()
in your loop to display the markers like so:
Marker marker = mMap.addMarker(markerOptions);
marker.showInfoWindow();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论