Code example for MarkerOptions

Methods: iconposition

0
package in.wptrafficanalyzer.locationroutedirectionmapv2; 
 
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.InputStreamReader; 
import java.net.HttpURLConnection; 
import java.net.URL; 
import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 
 
import org.json.JSONObject; 
 
import android.graphics.Color; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.util.Log; 
import android.view.Menu; 
 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.GoogleMap.OnMapClickListener; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.BitmapDescriptorFactory; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 
import com.google.android.gms.maps.model.PolylineOptions; 
 
 
public class MainActivity extends FragmentActivity { 
 
	GoogleMap map;
	ArrayList<LatLng> markerPoints;
	 
	@Override 
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main); 
		 
		// Initializing  
		markerPoints = new ArrayList<LatLng>();
		 
		// Getting reference to SupportMapFragment of the activity_main 
		SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
		 
		// Getting Map for the SupportMapFragment 
		map = fm.getMap();		
		 
		if(map!=null){
		 
			// Enable MyLocation Button in the Map 
			map.setMyLocationEnabled(true);		
			 
			// Setting onclick event listener for the map 
			map.setOnMapClickListener(new OnMapClickListener() {
				 
				@Override 
				public void onMapClick(LatLng point) {
					 
					// Already two locations				 
					if(markerPoints.size()>1){
						markerPoints.clear();
						map.clear();					
					} 
					 
					// Adding new item to the ArrayList 
					markerPoints.add(point);				
					 
					// Creating MarkerOptions 
					MarkerOptions options = new MarkerOptions();
					 
					// Setting the position of the marker 
					options.position(point);
					 
					/**  
					 * For the start location, the color of marker is GREEN and 
					 * for the end location, the color of marker is RED. 
					 */ 
					if(markerPoints.size()==1){
						options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
					}else if(markerPoints.size()==2){
						options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
					} 
								 
					 
					// Add new marker to the Google Map Android API V2 
					map.addMarker(options);