google maps v2 not showing multiple markers

风格不统一 提交于 2020-01-06 17:41:14

问题


I am trying to add multiple markers in GoogleMaps. I am using Google Map Android API v2. Before asking this question i read this and this links and a few more links. Please see my code:

for (PostList post : postList) 
{       Log.d("location", "latitude" + post.latitude);
        Log.d("location", "longitude" + post.longitude);
        double latitude = Double.parseDouble(post.latitude);
        double longitude = Double.parseDouble(post.longitude);
        //LatLng postPosition = new LatLng(latitude, longitude);
        LatLng postPosition = new LatLng(Float.parseFloat(post.latitude), Float.parseFloat(post.longitude));
        Log.d("location", "LatLng = " + postPosition);
        String title = "latitude = " + post.latitude + ", longitude = " + post.longitude;
        mMarkers.add(map.addMarker(new MarkerOptions(.position(postPosition).title(title)));
        Log.d("location", "Marker was added ");
}

and Logs:

09-15 14:44:47.080: D/location(2859): begin
09-15 14:44:47.080: D/location(2859): postSize = 10
09-15 14:44:47.080: D/location(2859): latitude55.74144460699403
09-15 14:44:47.080: D/location(2859): longitude37.669780254364014
09-15 14:44:47.090: D/location(2859): LatLng = lat/lng: (55.7414436340332,37.66978073120117)
09-15 14:44:47.100: D/location(2859): Marker was added 
09-15 14:44:47.100: D/location(2859): latitude55.75222
09-15 14:44:47.100: D/location(2859): longitude37.61556
09-15 14:44:47.100: D/location(2859): LatLng = lat/lng: (55.752220153808594,37.61555862426758)
09-15 14:44:47.100: D/location(2859): Marker was added 
09-15 14:44:47.100: D/location(2859): latitude55.75222
09-15 14:44:47.100: D/location(2859): longitude37.61556
09-15 14:44:47.100: D/location(2859): LatLng = lat/lng: (55.752220153808594,37.61555862426758)
09-15 14:44:47.120: D/location(2859): Marker was added 
09-15 14:44:47.120: D/location(2859): latitude55.75222
09-15 14:44:47.120: D/location(2859): longitude37.61556
09-15 14:44:47.120: D/location(2859): LatLng = lat/lng: (55.752220153808594,37.61555862426758)
09-15 14:44:47.120: D/location(2859): Marker was added 
09-15 14:44:47.120: D/location(2859): latitude55.75222
09-15 14:44:47.120: D/location(2859): longitude37.61556
09-15 14:44:47.120: D/location(2859): LatLng = lat/lng: (55.752220153808594,37.61555862426758)
09-15 14:44:47.130: D/location(2859): Marker was added 
09-15 14:44:47.130: D/location(2859): latitude55.75222
09-15 14:44:47.130: D/location(2859): longitude37.61556
09-15 14:44:47.130: D/location(2859): LatLng = lat/lng: (55.752220153808594,37.61555862426758)
09-15 14:44:47.130: D/location(2859): Marker was added 
09-15 14:44:47.130: D/location(2859): latitude55.75222
09-15 14:44:47.130: D/location(2859): longitude37.61556
09-15 14:44:47.130: D/location(2859): LatLng = lat/lng: (55.752220153808594,37.61555862426758)
09-15 14:44:47.130: D/location(2859): Marker was added 
09-15 14:44:47.130: D/location(2859): latitude55.75222
09-15 14:44:47.130: D/location(2859): longitude37.61556
09-15 14:44:47.130: D/location(2859): LatLng = lat/lng: (55.752220153808594,37.61555862426758)
09-15 14:44:47.140: D/location(2859): Marker was added 
09-15 14:44:47.140: D/location(2859): latitude55.75222
09-15 14:44:47.140: D/location(2859): longitude37.61556
09-15 14:44:47.140: D/location(2859): LatLng = lat/lng: (55.752220153808594,37.61555862426758)
09-15 14:44:47.140: D/location(2859): Marker was added 
09-15 14:44:47.140: D/location(2859): latitude55.75222
09-15 14:44:47.140: D/location(2859): longitude37.61556
09-15 14:44:47.140: D/location(2859): LatLng = lat/lng: (55.752220153808594,37.61555862426758)
09-15 14:44:47.150: D/location(2859): Marker was added 

In GoogleMap I see 2 markers, but there must be 10 markers. What am I doing wrong? Thank you.


回答1:


You see 2 markers because as you can see in the logcat, after second marker, all of markers have same latitute and longitude.



来源:https://stackoverflow.com/questions/25846607/google-maps-v2-not-showing-multiple-markers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!