Android Location - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Location class.

This code example shows how to use the following methods:getLatitude
	 
	private boolean isDiff(Location loc){
 
		if(result == null) return true; 
		 
		float diff = distFrom(result.getLatitude(), result.getLongitude(), loc.getLatitude(), loc.getLongitude());
		 
		if(diff < tolerance){
			AQUtility.debug("duplicate location"); 
			return false; 
		}else{ 
			return true; 
		} 
	} 
	 
	 
	private boolean isBetter(Location loc){
		 
		if(result == null) return true; 
		 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getLatitude, getLongitude
   
  LocationListener onLocation=new LocationListener() {
    public void onLocationChanged(Location location) { 
      StringBuilder buf=new StringBuilder("javascript:whereami("); 
       
      buf.append(String.valueOf(location.getLatitude())); 
      buf.append(","); 
      buf.append(String.valueOf(location.getLongitude())); 
      buf.append(")"); 
       
      browser.loadUrl(buf.toString()); 
    } 
     
    public void onProviderDisabled(String provider) { 
      // required for interface, not used 
    } 
     
    public void onProviderEnabled(String provider) { 
      // required for interface, not used 
    } 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getLatitude, getLongitude
		return new Point(aGP.getLongitudeE6(), aGP.getLatitudeE6());
	} 
 
	/** Converts an {@link Location} to an {@link Point}. */ 
	public static Point location2Point(final Location aLocation){
		return new Point((int) (aLocation.getLongitude() * 1E6),
				(int) (aLocation.getLatitude() * 1E6));
	} 
 
	/** Converts an {@link Location} to a {@link GeoPoint}. */ 
	public static GeoPoint location2GeoPoint(final Location aLocation){
		return new GeoPoint((int) (aLocation.getLatitude() * 1E6),
				(int) (aLocation.getLongitude() * 1E6));
	} 
 
	/** 
	 * Calculates the bearing of the two Locations supplied and returns the 
	 * Angle in the following (GPS-likely) manner: <br /> 
	 * <code>N:0°, E:90°, S:180°, W:270°</code> 
	 */ 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getAltitude, getBearing, getLatitude, getLongitude, getSpeed
	 
 
    public void onLocationChanged(Location location) {
      // Called when a new location is found by the network location provider. 
      //makeUseOfNewLocation(location); 
    	locationChanged(location.getAltitude(),location.getLatitude(),location.getLongitude(),location.getSpeed(),location.getBearing());
    } 
 
 
    public void onProviderEnabled(String provider) {}
 
    public void onProviderDisabled(String provider) {}
 
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub 
		 
	} 
	 
	 
	public static native void locationChanged(double altitude, double latitude, double longitude, float speed, float bearing);
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getLatitude, getLongitude
        Location location = ((LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE)).getLastKnownLocation("gps");
        return locationToLatLng(location);
    } 
 
    private LatLng locationToLatLng(Location location) {
        return new LatLng(location.getLatitude(), location.getLongitude());
    } 
 
} 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getTime
    ListenerRegistration(String provider, long minTime, float minDistance, Location locationAtCreation,
               LocationListener listener) {
      this.provider = provider;
      this.minTime = minTime;
      this.minDistance = minDistance;
      this.lastSeenTime = locationAtCreation == null ? 0 : locationAtCreation.getTime();
      this.lastSeenLocation = locationAtCreation;
      this.listener = listener;
    } 
  } 
 
  /** Mapped by provider. */ 
  private final Map<String, List<ListenerRegistration>> locationListeners =
      new HashMap<String, List<ListenerRegistration>>();
 
  @Implementation 
  public boolean isProviderEnabled(String provider) {
    LocationProviderEntry map = providersEnabled.get(provider);
    if (map != null) {
      Boolean isEnabled = map.getKey();
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getLatitude
    private double getCosineSunLocalHour(double sunTrueLong, double zenith) {
        double sinSunDeclination = getSinOfSunDeclination(sunTrueLong);
        double cosineSunDeclination = getCosineOfSunDeclination(sinSunDeclination);
 
        final double zenithInRads = Math.toRadians(zenith);
        final double latitude = Math.toRadians(mLocation.getLatitude());
 
        double cosineZenith = Math.cos(zenithInRads);
        double sinLatitude = Math.sin(latitude);
        double cosLatitude = Math.cos(latitude);
 
        double sinDeclinationTimesSinLat = sinSunDeclination * sinLatitude;
        double dividend = cosineZenith - sinDeclinationTimesSinLat;
        double divisor = cosineSunDeclination * cosLatitude;
 
        return dividend / divisor;
    } 
 
    private static double getSinOfSunDeclination(double sunTrueLong) {
        double sinTrueLongitude = Math.sin(Math.toRadians(sunTrueLong));
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getAccuracy, hasAccuracy
    		} 
	    } 
	} 
	 
	private boolean isAccurate(Location location) {
	    return !location.hasAccuracy() || location.getAccuracy() < 600;
	} 
 
	private boolean shouldUpdate(Location location) {
		boolean isAccurate;
		long elapsedMillis;
 
		// If the last update was null, use the current point 
		if (lastUpdate == null)
			return true; 
 
		elapsedMillis = System.currentTimeMillis() - lastUpdate.getTime();
		 
		// If not enough time has elapsed since the last point received, don't use this point 
		if(elapsedMillis < Util.getMinTime(this))
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getSpeed, hasSpeed
		_dateTime = new Date(location.getTime()); 
	} 
 
	public void CalculateSpeed(LocationIdentifier previousLocation)
	{ 
		if(_location.hasSpeed())
			_speed = _location.getSpeed();
		else 
		{ 
			double diff = (double)(getDateTime().getTime() - previousLocation.getDateTime().getTime());
			double distance = _location.distanceTo(previousLocation.getLocation());
			_speed = (float) (distance/diff * 3600.0) ;
		} 
		 
	} 
	 
	public double getLongitudeDegrees() 
	{ 
		return _location.getLongitude();
	} 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getLatitude, getLongitude
   
  LocationListener onLocation=new LocationListener() {
    public void onLocationChanged(Location location) { 
      StringBuilder buf=new StringBuilder("javascript:whereami("); 
       
      buf.append(String.valueOf(location.getLatitude())); 
      buf.append(","); 
      buf.append(String.valueOf(location.getLongitude())); 
      buf.append(")"); 
       
      browser.loadUrl(buf.toString()); 
    } 
     
    public void onProviderDisabled(String provider) { 
      // required for interface, not used 
    } 
     
    public void onProviderEnabled(String provider) { 
      // required for interface, not used 
    } 
10
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android Location Questions & Answers:

Other Android Location Examples

30:	    Criteria criteria = new Criteria();
31:	    provider = locationManager.getBestProvider(criteria, false);
32:	    Location location = locationManager.getLastKnownLocation(provider);
33:	
34:	    // Initialize the location fields
-
57:	
58:	  @Override
59:	  public void onLocationChanged(Location location) {
60:	    int lat = (int) (location.getLatitude());
61:	    int lng = (int) (location.getLongitude());

Read More

0:	public Location getLocation() {
1:			try {
2:				locationManager = (LocationManager) mContext
-
58:		}
59:		@Override
60:		public void onLocationChanged(Location location) {
61:		}
62:

Read More

26:		boolean canGetLocation = false;
27:	
28:		Location location = null; // location
29:		double latitude; // latitude
30:		double longitude; // longitude
-
44:		}
45:	
46:		public Location getLocation() {
47:			try {
48:				locationManager = (LocationManager) mContext
-
183:	
184:		@Override
185:		public void onLocationChanged(Location location) {
186:		}
187:

Read More

26:		boolean canGetLocation = false;
27:	
28:		Location location; // location
29:		double latitude; // latitude
30:		double longitude; // longitude
-
44:		}
45:	
46:		public Location getLocation() {
47:			try {
48:				locationManager = (LocationManager) mContext
-
179:	
180:		@Override
181:		public void onLocationChanged(Location location) {
182:		}
183:

Read More

See Code Examples for Android Location Methods: