Page 63

Android Programming Cookbook

55 / 143

public void initializeMapTraffic() { googleMap.setTrafficEnabled(true); } public void initializeMapType() { googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); }

public void initializeMapViewSettings() { googleMap.setIndoorEnabled(true); googleMap.setBuildingsEnabled(false); }

//this is method to help us set up a Marker that stores the Markers we want to plot ←on the map public void setUpMarkersHashMap() { if (markersHashMap == null) { markersHashMap = new HashMap(); } } //this is method to help us add a Marker into the hashmap that stores the Markers public void addMarkerToHashMap(CustomMarker customMarker, Marker marker) { setUpMarkersHashMap(); markersHashMap.put(customMarker, marker); } //this is method to help us find a Marker that is stored into the hashmap public Marker findMarker(CustomMarker customMarker) { iter = markersHashMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry mEntry = (Map.Entry) iter.next(); CustomMarker key = (CustomMarker) mEntry.getKey(); if (customMarker.getCustomMarkerId().equals(key.getCustomMarkerId() ←)) { Marker value = (Marker) mEntry.getValue(); return value; } } return null; }

//this is method to help us add a Marker to the map public void addMarker(CustomMarker customMarker) { MarkerOptions markerOption = new MarkerOptions().position( new LatLng(customMarker.getCustomMarkerLatitude(), ←customMarker.getCustomMarkerLongitude())).icon( BitmapDescriptorFactory.defaultMarker()); Marker newMark = googleMap.addMarker(markerOption); addMarkerToHashMap(customMarker, newMark); } //this is method to help us remove a Marker public void removeMarker(CustomMarker customMarker) { if (markersHashMap != null) { if (findMarker(customMarker) != null) { findMarker(customMarker).remove();

SKY MAGZ  

This is Yahya Christian School Magazine

Advertisement