Code example for PolygonOptions

Methods: strokeColor, strokeWidth, visible

0
package com.elias.insideglorias; 
 
import java.io.InputStream; 
import java.util.List; 
import java.util.Vector; 
 
import com.elias.kmlreader.ReaderKML; 
import com.elias.polygondouble.Point; 
import com.elias.polygondouble.Polygon; 
import com.elias.polygondouble.Polygon.Builder; 
import com.google.android.gms.maps.CameraUpdate; 
import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 
import com.google.android.gms.maps.model.PolygonOptions; 
 
import android.graphics.Color; 
import android.location.Criteria; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.location.LocationProvider; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.Menu; 
import android.widget.Toast; 
import android.support.v4.app.FragmentActivity; 
 
public class MainActivity extends FragmentActivity { 
	 
	int precision;
	boolean hasAlt;
	int powerConsum;
	boolean inside;
	GoogleMap map = null;
	LocationManager locManager;
	List<String> providersList;
	LocationProvider provider;
	Location location;	
	Criteria req;
	LocationListener locListener;
	CameraUpdate camUpd1;		    
	// 
	Vector<Point> lista;
	Vector<Point> testin;
	Vector<Point> testout;
	Polygon glorias;
	 
	ReaderKML kmlReader;
	InputStream input_kml;
 
 
	@Override 
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main); 
		 
		map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
		 
		locManager = (LocationManager)getSystemService(LOCATION_SERVICE);
		providersList = locManager.getAllProviders();
		provider =locManager.getProvider(providersList.get(0));
		precision = provider.getAccuracy();
		req = new Criteria();
		req.setAccuracy(Criteria.ACCURACY_FINE);		
		inside = false;
 
		map.setMyLocationEnabled(true);
		map.getUiSettings().setMyLocationButtonEnabled(true);
		map.getUiSettings().setCompassEnabled(true);
		map.setTrafficEnabled(false);
		 
		buildPolygon(); 
		drawPolygon(); 
		startLocalization(); 
	} 
 
	 
 
	private void startLocalization() { 
		if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
			showInformation("El GPS está deshabilidato"); 
		} 
		else { 
			location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
		} 
		 
		camUpd1 = CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()),15);		 
		map.moveCamera(camUpd1);
	 
		//showMarker(location);		 
		testInside(location);
		 
		locListener = new LocationListener() {
			 
			@Override 
		    public void onLocationChanged(Location location) {
				//showMarker(location); 
				//showMarker(map.getMyLocation()); 
				//testInside(location); 
				testInside(map.getMyLocation());
		    } 
			@Override 
		    public void onProviderDisabled(String provider){
				showInformation("GPS apagado"); 
		    } 
			@Override 
		    public void onProviderEnabled(String provider){
				showInformation("GPS encendido"); 
		    } 
			@Override 
		    public void onStatusChanged(String provider, int status, Bundle extras){
				//showInformation("Provider Status: " + status); 
		    } 
		}; 
		 
		locManager.requestLocationUpdates(
    			LocationManager.GPS_PROVIDER, 5000, 0, locListener); // cada 10 segundos
	} 
 
	private void showMarker(Location loc) {
		 
		map.addMarker(new MarkerOptions()
        .position(new LatLng(loc.getLatitude(), loc.getLongitude()))
        .title("Posicion actual"));
	} 
	 
	private void drawPolygon() 
	{ 
		PolygonOptions polyoptions = new PolygonOptions();
		for(int i =0;i<lista.size();i++) {
 
			polyoptions.add(new LatLng(lista.get(i).getX(),lista.get(i).getY()));
		} 
		polyoptions.strokeColor(Color.BLUE);
		polyoptions.strokeWidth(10);
		polyoptions.visible(true);
		map.addPolygon(polyoptions);
	}