Code example for CircleOptions

Methods: center, fillColor, radius, strokeColor

0
package com.example.remindmeby; 
 
import java.io.IOException; 
import java.util.List; 
 
import android.app.Dialog; 
import android.content.Context; 
import android.location.Address; 
import android.location.Criteria; 
import android.location.Geocoder; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.view.Menu; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.View.OnFocusChangeListener; 
import android.view.View.OnTouchListener; 
import android.view.inputmethod.InputMethodManager; 
import android.widget.Button; 
import android.widget.EditText; 
 
import com.google.android.gms.common.ConnectionResult; 
import com.google.android.gms.common.GooglePlayServicesUtil; 
import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.GoogleMap.OnMapClickListener; 
import com.google.android.gms.maps.GoogleMap.OnMarkerDragListener; 
import com.google.android.gms.maps.LocationSource; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.UiSettings; 
import com.google.android.gms.maps.model.BitmapDescriptorFactory; 
import com.google.android.gms.maps.model.Circle; 
import com.google.android.gms.maps.model.CircleOptions; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.Marker; 
import com.google.android.gms.maps.model.MarkerOptions; 
 
public class SelectPointActivity extends FragmentActivity implements 
		LocationListener, LocationSource, OnClickListener {
	private GoogleMap mMap;
	private UiSettings mUiSettings;
	private LocationManager locationManager;
	private String provider;
	private OnLocationChangedListener mListener;
	private Button btnSearchMap;
	private EditText etSearchMap;
	private EditText etRadius;
	private Address address;
	private double convertLongi;
	private double convertLati;
	CircleOptions coRadius;
	Location location;
	LatLng markerCenter;
	Location from;
	Location to;
	private static  double  AVERAGE_RADIUS_OF_EARTH = 6378.16;
	@Override 
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_select_point); 
		setUpMapIfNeeded(); 
		// Getting Google Play availability status 
		int status = GooglePlayServicesUtil
				.isGooglePlayServicesAvailable(getBaseContext());
 
		// Showing status 
		if (status != ConnectionResult.SUCCESS) { // Google Play Services are
													// not available 
 
			int requestCode = 10;
			Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this,
					requestCode);
			dialog.show();
 
		} else { // Google Play Services are available 
 
			// Getting reference to the SupportMapFragment of activity_main.xml 
			SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
					.findFragmentById(R.id.map); 
 
			// Enabling MyLocation Layer of Google Map 
			mMap.setMyLocationEnabled(true);
 
			// Getting LocationManager object from System Service 
			// LOCATION_SERVICE 
			LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
 
			// Creating a criteria object to retrieve provider 
			Criteria criteria = new Criteria();
 
			// Getting the name of the best provider 
			String provider = locationManager.getBestProvider(criteria, true);
 
			etSearchMap = (EditText) findViewById(R.id.etSearchMap);
			etRadius = (EditText) findViewById(R.id.etRadius);
			btnSearchMap = (Button) findViewById(R.id.btnSearchMap);
 
			etRadius.setOnFocusChangeListener(new myOnFocusChangeListener());
 
			// Getting Current Location 
			location = locationManager.getLastKnownLocation(provider);
			mMap.setLocationSource(this);
			mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
					location.getLatitude(), location.getLongitude()), 18.5f));
 
			/* 
			 * Circle circle = mMap.addCircle(new CircleOptions() .center(new 
			 * LatLng(location.getLatitude(),location.getLongitude()) 
			 * .radius(10000) .strokeColor(Color.RED) .fillColor(Color.BLUE)); 
			 */ 
			if (location != null) {
				// PLACE THE INITIAL MARKER 
				// drawMarker(location); 
			} 
			locationManager.requestLocationUpdates(provider, 20000, 0, this);
		} 
 
		btnSearchMap.setOnClickListener(this);
	} 
 
	@Override 
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present. 
		getMenuInflater().inflate(R.menu.select_point, menu);
		return true; 
	} 
 
	private void setUpMapIfNeeded() { 
		// Do a null check to confirm that we have not already instantiated the 
		// map. 
		if (mMap == null) {
			// Try to obtain the map from the SupportMapFragment. 
			mMap = ((SupportMapFragment) getSupportFragmentManager()
					.findFragmentById(R.id.map)).getMap();
			// Check if we were successful in obtaining the map. 
			if (mMap != null) {
				setUpMap(); 
			} 
		} 
		 
	} 
 
	private void setUpMap() { 
		// mMap.addMarker(new MarkerOptions().position(new LatLng(0, 
		// 0)).title("Marker")); 
		mUiSettings = mMap.getUiSettings();
		mUiSettings.setAllGesturesEnabled(true);
		mUiSettings.setRotateGesturesEnabled(true);
		mUiSettings.setMyLocationButtonEnabled(true);
		mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
		mMap.setOnMapClickListener(new myOnMapClickListener());
	} 
 
	@Override 
	public void activate(OnLocationChangedListener arg0) {
		// TODO Auto-generated method stub 
 
	} 
 
	@Override 
	public void deactivate() { 
		// TODO Auto-generated method stub 
 
	} 
 
	@Override 
	public void onLocationChanged(Location location) {
		// location = locationManager.getLastKnownLocation(provider); 
		if (mListener != null) {
			mListener.onLocationChanged(location);
 
			mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
					location.getLatitude(), location.getLongitude()), 18.5f));
		} 
 
	} 
 
	@Override 
	public void onProviderDisabled(String arg0) {
		// TODO Auto-generated method stub 
 
	} 
 
	@Override 
	public void onProviderEnabled(String arg0) {
		// TODO Auto-generated method stub 
 
	} 
 
	@Override 
	public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
		// TODO Auto-generated method stub 
 
	} 
 
	@Override 
	public void onClick(View v) {
 
		String usrLoc = etSearchMap.getText().toString();
		Geocoder gc = new Geocoder(this);
		List<Address> addr; // list of address
		try { 
			addr = gc.getFromLocationName(usrLoc, 2);// maximum 2 results
			if (addr.size() > 0) {
				address = addr.get(0);
				convertLongi = address.getLongitude();
				convertLati = address.getLatitude();
				// GeoPoint gp = new GeoPoint((int)(convertLati * 1E6), 
				// (int)(convertLongi * 1E6)); 
				mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
						new LatLng(address.getLatitude(), address
								.getLongitude()), 13.5f));
				InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
				imm.hideSoftInputFromWindow(etSearchMap.getWindowToken(), 0);
			} 
		} catch (IOException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		} 
	} 
 
	public void drawRadius(int size,LatLng location) {
		coRadius = new CircleOptions();
		coRadius.center(location);
		if (size == 0) {
			coRadius.radius(10);
		} else { 
 
			coRadius.radius(size);
		} 
		coRadius.fillColor(0x110000FF);
		coRadius.strokeColor(0xFF0000FF);
		Circle circle = mMap.addCircle(coRadius);
	} 
public void drawMarker(LatLng location)
{ 
MarkerOptions moMarker = new MarkerOptions();