Reputation: 1360
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.
Upvotes: 0
Views: 353
Reputation: 478
You see 2 markers because as you can see in the logcat, after second marker, all of markers have same latitute and longitude.
Upvotes: 2