Code example for GoogleMap

Methods: addMarker, getMyLocation

0
		} 
	} 
 
	public void refresh(){ 
		if(currentLoc && fromPosition != null) {
			Location loc = mapView.getMyLocation();
			fromPosition = new LatLng(loc.getLatitude(),loc.getLongitude());
			setFromMarker("From"); 
		} 
		if(toPosition != null) {
			findDirections(); 
		} 
	} 
 
	@Override 
	public void onMapLongClick(LatLng point) {
 
		LatLng temp = new LatLng(point.latitude, point.longitude);
		Marker marker = setClickMarker(temp, getAddress(point));
		marker.showInfoWindow();
	} 
 
	// needs refactoring 
	@Override 
	public void onMapClick(LatLng point) {
		Log.d(TAG, "Clicked"+point.latitude+","+point.longitude);
		if (currentLoc) {
			Location loc = mapView.getMyLocation();
			if(loc == null){
				Toast.makeText(this, "Waiting for current location.", Toast.LENGTH_SHORT).show();
			} else { 
				fromPosition = new LatLng(loc.getLatitude(),loc.getLongitude());
				toPosition = point;
				setFromMarker("From"); 
				setToMarker("To"); 
				findDirections(); 
			} 
		} else { 
			if (fromPosition == null) {
				fromPosition = point;
				setFromMarker("From"); 
			} else if (toPosition == null) {
				toPosition = point;
				setToMarker("To"); 
				findDirections(); 
			} else { 
				removeTo(true); 
				fromPosition = point;
				setFromMarker("From"); 
				Toast.makeText(this, "Click TO location", Toast.LENGTH_SHORT).show();
			} 
		} 
 
	} 
 
	public String getAddress(LatLng point) {
 
		Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
		String strCompleteAddress = "";
		try { 
			List<Address> addresses = geoCoder.getFromLocation(point.latitude,  point.longitude, 1);
			for (int j=0; j<addresses.get(0).getMaxAddressLineIndex();j++) {
				strCompleteAddress+= addresses.get(0).getAddressLine(j) + "\n";
			} 
		} catch (IOException e) {
			Log.i("MyLocTAG => ", "this is the exception part");
			e.printStackTrace();
		} 
		return strCompleteAddress;
	} 
 
	//.snippet("Population: 4,137,400") is gray text below title on marker info windows 
 
	public void setToMarker(String s){
		removeTo(false); 
		toMarker = mapView.addMarker(new MarkerOptions()
		.position(toPosition).title(s)
		.draggable(true).icon(BitmapDescriptorFactory
				.defaultMarker(BitmapDescriptorFactory.HUE_RED)));
	} 
 
	public void setFromMarker(String s){
		removeFrom(false); 
		fromMarker =  mapView.addMarker(new MarkerOptions()
		.position(fromPosition).title(s)
		.draggable(true).icon(BitmapDescriptorFactory
				.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));
 
	}