Posts

Showing posts with the label Google Maps Android Api 2

Adding Custom Property To Marker (Google Map Android API V2)

Answer : You cannot directly extend Marker , because it is a final class, but you have some options: 0) As of Google Maps Android API v2 version 9.4.0, you can use Marker::getTag and Marker::setTag . This is most likely the preferred option. 1) Create a map to store all additional information: private Map<Marker, MyData> allMarkersMap = new HashMap<Marker, MyData>(); When creating a marker, add it to this map with your data: Marker marker = map.addMarker(...); allMarkersMap.put(marker, myDataObj); Later in your render function: MyData myDataObj = allMarkersMap.get(marker); if (myDataObj.customProp) { ... 2) Another way would be to use Marker.snippet to store all the info as a String and later parse it, but that's kinda ugly and unmaintainable solution. 3) Switch from plain Google Maps Android API v2 to Android Maps Extensions. This is very similar to point 1, but you can directly store MyData into marker, using marker.setData(myDataObj)...

Change Position Of Google Maps API's "My Location" Button

Answer : You can get the "My Location" button and move it, like : public class MapFragment extends SupportMapFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View mapView = super.onCreateView(inflater, container, savedInstanceState); // Get the button view View locationButton = ((View) mapView.findViewById(1).getParent()).findViewById(2); // and next place it, for exemple, on bottom right (as Google Maps app) RelativeLayout.LayoutParams rlp = (RelativeLayout.LayoutParams) locationButton.getLayoutParams(); // position on right bottom rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0); rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); rlp.setMargins(0, 0, 30, 30); } } Just use GoogleMap.setPadding(left, top, right, bottom), which allows you to indicate parts of the map that may be obscured by other views. Setting padding re-positions the s...

Clear Markers From Google Map In Android

Answer : If you want to clear "all markers, overlays, and polylines from the map", use clear() on your GoogleMap . If you do not wish to clear polylines and only the markers need to be removed follow the steps below. First create a new Marker Array like below List<Marker> AllMarkers = new ArrayList<Marker>(); Then when you add the marker on the google maps also add them to the Marker Array (its AllMarkers in this example) for(int i=0;i<places.length();i++){ LatLng location = new LatLng(Lat,Long); MarkerOptions markerOptions = new MarkerOptions(); markerOptions.position(location); markerOptions.title("Your title"); Marker mLocationMarker = Map.addMarker(markerOptions); // add the marker to Map AllMarkers.add(mLocationMarker); // add the marker to array } then finally call the below method to remove all markers at once ...