I am trying to add multiple markers on GoogleMap
. This is what I am doing:
private void initilizeMap() {
try {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager()
.findFragmentById(R.id.map)).getMap();
// Enabling MyLocation Layer of Google Map
googleMap.setMyLocationEnabled(true);
if (googleMap != null)
addMarkers();
// Getting LocationManager object from System Service
// LOCATION_SERVICE
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// Creating a criteria object to retrieve provider
Criteria criteria = new Criteria();
// Getting the name of the best provider
String provider = locationManager.getBestProvider(criteria,
true);
// Getting Current Location
Location location = locationManager
.getLastKnownLocation(provider);
if (location != null) {
onLocationChanged(location);
}
locationManager
.requestLocationUpdates(provider, 20000, 0, this);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
Following function adds markers:
private void addMarkers() {
try {
for (String title : locations.keySet()) {
if (locations.get(title).getLatitude() != 0
&& locations.get(title).getLongitude() != 0) {
// create marker
MarkerOptions marker = new MarkerOptions().position(
new LatLng(locations.get(title).getLatitude(),
locations.get(title).getLongitude()))
.title(title);
marker.icon(BitmapDescriptorFactory
.fromResource(R.drawable.pin_map));
// adding marker
googleMap.addMarker(marker);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
But markers are not displaying, though they are adding up on GoogleMap which I checked while debugging. No exception coming as well. I tried to change the icon image, still not working.
You are most probably using the old int values for latitude/longitude as they where expected for the GeoPoint of the previous GoogleMaps API. These are 1 million times too big for the new LatLng object, which expects double values rather than integers.