与Google地图上标记显示相关的问题

huangapple go评论64阅读模式
英文:

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 &lt; 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();

huangapple
  • 本文由 发表于 2020年8月21日 11:24:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/63516069.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定