Code example for LatLng

0
/** 
 * @copyright 2012 City of Bloomington, Indiana 
 * @license http://www.gnu.org/licenses/gpl.txt GNU/GPL, see LICENSE.txt 
 * @author Cliff Ingham <inghamn@bloomington.in.gov> 
 */ 
package gov.in.bloomington.georeporter.activities; 
 
import com.actionbarsherlock.app.SherlockFragmentActivity; 
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 gov.in.bloomington.georeporter.R; 
import gov.in.bloomington.georeporter.models.Open311; 
import android.content.Intent; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.view.View; 
 
public class ChooseLocationActivity extends SherlockFragmentActivity { 
	private GoogleMap mMap;
	private LocationManager mLocationManager;
	private MapListener mLocationListener;
	 
	public static final int UPDATE_GOOGLE_MAPS_REQUEST = 0;
	 
	public static final int DEFAULT_ZOOM = 17;
	 
	@Override 
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map_chooser); 
        setUpMapIfNeeded(); 
	} 
	 
	@Override 
	protected void onResume() { 
	    super.onResume(); 
	    setUpMapIfNeeded(); 
	} 
	 
    /** 
     * Sets up the map if it is possible to do so (i.e., the Google Play services APK is correctly 
     * installed) and the map has not already been instantiated.. This will ensure that we only ever 
     * call {@link #setUpMap()} once when {@link #mMap} is not null. 
     * <p> 
     * If it isn't installed {@link SupportMapFragment} (and 
     * {@link com.google.android.gms.maps.MapView 
     * MapView}) will show a prompt for the user to install/update the Google Play services APK on 
     * their device. 
     * <p> 
     * A user can return to this Activity after following the prompt and correctly 
     * installing/updating/enabling the Google Play services. Since the Activity may not have been 
     * completely destroyed during this process (it is likely that it would only be stopped or 
     * paused), {@link #onCreate(Bundle)} may not be called again so we should call this method in 
     * {@link #onResume()} to guarantee that it will be called. 
     */ 
    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(); 
            } 
        } 
    } 
 
    /** 
     * This is where we can add markers or lines, add listeners or move the camera. 
     * <p> 
     * This should only be called once and when we are sure that {@link #mMap} is not null. 
     */ 
    private void setUpMap() { 
        mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        mMap.setMyLocationEnabled(false);
        mMap.moveCamera(CameraUpdateFactory.zoomTo(DEFAULT_ZOOM));
    } 
 
	@Override 
	protected void onStart() { 
		super.onStart(); 
		 
		mLocationListener = new MapListener();
		 
		mLocationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
		 
        if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,     0, 0, mLocationListener);
        } 
		if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
	        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mLocationListener);
		} 
	} 
 
	private class MapListener implements LocationListener {
        private static final int TWO_MINUTES = 1000 * 60 * 2;
	    private Location mCurrentBestLocation;
	     
		@Override 
		public void onLocationChanged(Location location) {
		    if (isBetterLocation(location, mCurrentBestLocation)) {
		        mLocationManager.removeUpdates(this);
		    } 
		     
		    LatLng p = new LatLng(location.getLatitude(), location.getLongitude());
		    mMap.moveCamera(CameraUpdateFactory.newLatLng(p));
		} 
 
		@Override 
		public void onProviderDisabled(String provider) {
Experience pair programming with AI  Get Codota for Java