Code example for GoogleMap

Methods: addCircle, addMarker, clear, getCameraPosition, setLocationSource, setMapType, setMyLocationEnabled

0
	public MapHelperClass(GoogleMap map, int distanceWhenWPReached) {
 
		this.map = map;
		this.distanceWhenWPReached = distanceWhenWPReached;
 
		map.setMyLocationEnabled(true);
		map.setLocationSource(this);
		map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
 
		CleanMap(); 
	} 
 
	public void RedrawLines() { 
		if (WPPathPolyLine != null) {
			WPPathPolyLine.remove();
			WPPathPolyLine = null;
		} 
		PolylineOptions polylineOptions = new PolylineOptions().color(Color.CYAN).width(4);
		for (Marker m : markers) {
			polylineOptions.add(m.getPosition());
		} 
		WPPathPolyLine = map.addPolyline(polylineOptions);
 
	} 
 
	public void DrawFlightPath(LatLng copterPositionLatLng) {
		if (FlyingPathPoints.size() == 0) {
			FlyingPathPoints.add(copterPositionLatLng);
			return; 
		} 
 
		if (gps2m(copterPositionLatLng.latitude, copterPositionLatLng.longitude, FlyingPathPoints.get(FlyingPathPoints.size() - 1).latitude, FlyingPathPoints.get(FlyingPathPoints.size() - 1).longitude) > 5) {
			FlyingPathPoints.add(copterPositionLatLng);
 
			if (FlyingPathPoints.size() > FlyingPathPointsCount) {
				FlyingPathPoints.remove(0);
			} 
 
			if (FlightPathPolyLine != null) {
				FlightPathPolyLine.remove();
				FlightPathPolyLine = null;
			} 
 
			PolylineOptions polylineOptions = new PolylineOptions().color(Color.argb(100, 0, 255, 255));
			for (LatLng p : FlyingPathPoints) {
				polylineOptions.add(p);
			} 
			FlightPathPolyLine = map.addPolyline(polylineOptions);
		} 
	} 
 
	public void AddMarker() { 
		LatLng mapCenter = map.getCameraPosition().target;
		Marker m = map.addMarker(new MarkerOptions().position(mapCenter).draggable(true).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
		markers.add(m);
 
		int i = 1;
		for (Marker mm : markers) {
			mm.setTitle("WP#" + String.valueOf(i));
			i++;
		} 
		RedrawLines(); 
	} 
 
	public void AddMarker(LatLng position) {
		Marker m = map.addMarker(new MarkerOptions().position(position).draggable(true).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
		markers.add(m);
 
		int i = 1;
		for (Marker mm : markers) {
			mm.setTitle("WP#" + String.valueOf(i));
			i++;
		} 
		RedrawLines(); 
	} 
 
	public void CleanMap() { 
		markers = new ArrayList<Marker>();
		map.clear();
		addDefaultMarkersToMap(); 
	} 
 
	public void RemoveMarker(int position) {
		markers.get(position).remove();
		markers.remove(position);
	} 
 
	void addDefaultMarkersToMap() { 
		LatLng mapCenter = map.getCameraPosition().target;
		HomeMarker = map.addMarker(new MarkerOptions().position(mapCenter).title("Home").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)).draggable(true));
		PositionHoldMarker = map.addMarker(new MarkerOptions().position(mapCenter).title("PositionHold").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
		CurrentWPCircle = map.addCircle(new CircleOptions().center(mapCenter).radius(distanceWhenWPReached).fillColor(Color.argb(50, 0, 255, 50)));
		CurrentWPCircle.setStrokeWidth(2);
	} 
 
	@Override 
	public void activate(OnLocationChangedListener onLocationChangedListener) {