Java Code Examples for android.location.Location

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/activity/.

Source file: AirCastingMapActivity.java

  22 
vote

private void initializeMap(){
  mapView.setSatellite(settingsHelper.isSatelliteView());
  if (settingsHelper.isFirstLaunch()) {
    mapView.getController().setZoom(16);
    Location location=locationHelper.getLastLocation();
    if (location != null) {
      GeoPoint geoPoint=geoPoint(location);
      mapView.getController().setCenter(geoPoint);
    }
    settingsHelper.setFirstLaunch(false);
  }
}
 

Example 2

From project Airports, under directory /src/com/nadmm/airports/afd/.

Source file: NearbyAirportsFragment.java

  22 
vote

@Override public void onActivityCreated(Bundle savedInstanceState){
  Bundle args=getArguments();
  Location location=(Location)args.get(LocationColumns.LOCATION);
  if (location != null) {
    onLocationChanged(location);
  }
  super.onActivityCreated(savedInstanceState);
}
 

Example 3

From project android-context, under directory /src/edu/fsu/cs/contextprovider/map/.

Source file: AddPlaceMapActivity.java

  22 
vote

@Override public void onStart(){
  super.onStart();
  String provider=locationManager.getBestProvider(criteria,true);
  if (provider != null) {
    Location location=locationManager.getLastKnownLocation(provider);
    update(location);
    locationManager.requestLocationUpdates(provider,60000,1000,locationListener);
  }
}
 

Example 4

From project androidquery, under directory /beta/com/androidquery/callback/.

Source file: LocationAjaxCallback.java

  22 
vote

private Location getBestLocation(){
  Location loc1=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  Location loc2=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
  if (loc2 == null)   return loc1;
  if (loc1 == null)   return loc2;
  if (loc1.getTime() > loc2.getTime()) {
    return loc1;
  }
 else {
    return loc2;
  }
}
 

Example 5

From project android_packages_apps_Gallery, under directory /src/com/android/camera/.

Source file: Camera.java

  22 
vote

private Location getCurrentLocation(){
  for (int i=0; i < mLocationListeners.length; i++) {
    Location l=mLocationListeners[i].current();
    if (l != null)     return l;
  }
  return null;
}
 

Example 6

From project android_packages_apps_QiblaCompass, under directory /src/com/farsitel/qiblacompass/activities/.

Source file: QiblaActivity.java

  22 
vote

private void useDefaultLocation(SharedPreferences perfs,String key){
  int defLocationID=Integer.parseInt(perfs.getString(key,"" + LocationEnum.MENU_TEHRAN.getId()));
  LocationEnum locationEnum=LocationEnum.values()[defLocationID - 1];
  Location location=locationEnum.getLocation();
  qiblaManager.onLocationChanged(location);
  this.setLocationText(String.format(getString(R.string.default_location_text),locationEnum.getName(this)));
  onGPSOff(location);
}
 

Example 7

From project CityBikes, under directory /src/net/homelinux/penecoptero/android/citybikes/app/.

Source file: Locator.java

  22 
vote

public Location getLastKnownLocation(){
  Location location=locationManager.getLastKnownLocation("gps");
  if (location == null) {
    location=locationManager.getLastKnownLocation("network");
  }
  if (location == null && fallbackLocation != null) {
    location=fallbackLocation;
  }
  return location;
}
 

Example 8

From project Cura, under directory /src/com/cura/security/.

Source file: SMSService.java

  22 
vote

private void getFirstLocation(){
  Location location=locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  if (location != null) {
    latitude=location.getLatitude();
    longitude=location.getLongitude();
  }
}
 

Example 9

From project cw-advandroid, under directory /WebView/GeoWeb1/src/com/commonsware/android/geoweb/.

Source file: GeoWebOne.java

  22 
vote

public String getLocation() throws JSONException {
  Location loc=myLocationManager.getLastKnownLocation(PROVIDER);
  if (loc == null) {
    return (null);
  }
  JSONObject json=new JSONObject();
  json.put("lat",loc.getLatitude());
  json.put("lon",loc.getLongitude());
  return (json.toString());
}
 

Example 10

From project cw-omnibus, under directory /Internet/Weather/src/com/commonsware/android/weather/.

Source file: WeatherFragment.java

  22 
vote

@Override protected String doInBackground(Location... locs){
  String page=null;
  try {
    Location loc=locs[0];
    String url=String.format(template,loc.getLatitude(),loc.getLongitude());
    page=generatePage(buildForecasts(getForecastXML(url)));
  }
 catch (  Exception e) {
    this.e=e;
  }
  return (page);
}
 

Example 11

From project fanfoudroid, under directory /src/com/ch_linghu/fanfoudroid/service/.

Source file: LocationService.java

  22 
vote

public static LocationService test(Context context){
  LocationService ls=new LocationService(context);
  ls.startService();
  ls.logAllProviders();
  Location local=ls.getLastKnownLocation();
  if (local != null) {
    Log.v("LDS",ls.getLastKnownLocation().toString());
  }
  return ls;
}
 

Example 12

From project Gaggle, under directory /src/com/geeksville/gaggle/.

Source file: ListWaypointsActivity.java

  22 
vote

private void handleAddWaypoint(){
  GaggleApplication app=((GaggleApplication)getApplication());
  Location myloc=null;
  if (gps != null && gps.get() != null)   myloc=gps.get().getLastKnownLocation();
  if (myloc == null)   Toast.makeText(ListWaypointsActivity.this,R.string.can_not_add_waypoint_still_waiting_for_gps_fix,Toast.LENGTH_LONG).show();
 else {
    java.util.Date now=new java.util.Date();
    String name=DateFormat.format("yy/MM/dd kk:mm:ss",now).toString();
    ExtendedWaypoint w=new ExtendedWaypoint(name,myloc.getLatitude(),myloc.getLongitude(),(int)myloc.getAltitude(),0,Waypoint.Type.Unknown.ordinal());
    app.getWaypoints().add(w);
    myCursor.requery();
    Toast.makeText(ListWaypointsActivity.this,R.string.waypoint_created,Toast.LENGTH_SHORT).show();
  }
}
 

Example 13

From project 4308Cirrus, under directory /tendril-cirrus/src/main/java/edu/colorado/cs/cirrus/cirrus/.

Source file: TendrilLocationService.java

  21 
vote

public void onLocationChanged(Location loc){
  Location home=new Location(manager.GPS_PROVIDER);
  PreferenceUtils prefs=new PreferenceUtils(getApplicationContext());
  home.setLatitude(prefs.getHomeLatitude());
  home.setLongitude(prefs.getHomeLongitude());
  ActivityManager activityManager=(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
  ;
  Boolean appOpen=false;
  List<RunningAppProcessInfo> appProcesses=activityManager.getRunningAppProcesses();
  for (  RunningAppProcessInfo appProcess : appProcesses) {
    if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND && appProcess.processName.equals("edu.colorado.cs.cirrus.cirrus")) {
      appOpen=true;
    }
  }
  if (appOpen == false && prefs.getSmartHeat()) {
    if (loc.distanceTo(home) * 0.0006214 > prefs.getGpsRadius()) {
      try {
        TendrilTemplate.get().useAccessToken(prefs.getAccessToken());
        TendrilTemplate.get().setTstatSetpoint(prefs.getAwayTemp());
      }
 catch (      TendrilException e) {
        Toast.makeText(getApplicationContext(),e.getLocalizedMessage(),Toast.LENGTH_LONG).show();
        e.printStackTrace();
      }
    }
 else {
      try {
        TendrilTemplate.get().useAccessToken(prefs.getAccessToken());
        TendrilTemplate.get().setTstatSetpoint(prefs.getHomeTemp());
      }
 catch (      TendrilException e) {
        Toast.makeText(getApplicationContext(),e.getLocalizedMessage(),Toast.LENGTH_LONG).show();
        e.printStackTrace();
      }
    }
  }
}
 

Example 14

From project AmDroid, under directory /AmDroid/src/main/java/com/jaeckel/amenoid/fragments/.

Source file: AmenListFragment.java

  21 
vote

@Override protected List<Amen> wrappedDoInBackground(Category... categories) throws IOException {
  List<Amen> amens=new ArrayList<Amen>();
  for (  Category category : categories) {
    Log.d(TAG,"Loader executing with category: " + category);
    service=AmenoidApp.getInstance().getService();
    Log.d(TAG," Loader executing with service: " + service);
    Double lat=null;
    Double lng=null;
    Location lastLocation=AmenoidApp.getInstance().getLastLocation();
    Log.d(TAG,"---> LastLocation: " + lastLocation);
    if (lastLocation != null) {
      lat=lastLocation.getLatitude();
      lng=lastLocation.getLongitude();
    }
    amens=service.getAmenForCategory(category.getId(),0,lat,lng);
  }
  return amens;
}
 

Example 15

From project android-joedayz, under directory /Proyectos/androidMDWCompleto/src/com/android/mdw/demo/.

Source file: Main.java

  21 
vote

/** 
 * Called when the activity is first created. 
 */
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  MapView mapView=(MapView)findViewById(R.id.mapview);
  mapView.setBuiltInZoomControls(true);
  LocationManager locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
  Criteria criteria=new Criteria();
  Location location=null;
  String best=locationManager.getBestProvider(criteria,true);
  System.out.println("\nBest provider is: " + best);
  System.out.println("\nLocations (starting with last known):");
  if (best != null) {
    location=locationManager.getLastKnownLocation(best);
  }
  updateLocation(location);
  locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,100,1,this);
}
 

Example 16

From project Android_1, under directory /SharedNotepad/src/com/example/android/notepad/sharednotepadclient/.

Source file: NotepadSharedObject.java

  21 
vote

protected void sendLocationChanged(Location location){
  System.out.println("onLocationChanged location=" + location);
  if (location == null)   location=new Location("gps");
  try {
    sendSharedObjectMsgTo(null,SharedObjectMsg.createMsg(HANDLE_LOCATION_MSG,new Object[]{getLocalContainerID(),username,new Double(location.getLatitude()),new Double(location.getLongitude()),new Double(location.getAltitude())}));
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Example 17

From project android_7, under directory /src/org/immopoly/android/helper/.

Source file: LocationHelper.java

  21 
vote

public static void getLastLocationFromProvider(Context context){
  Location lastLocation=null;
  try {
    getCriteria(context);
    lastLocation=mLocationManager.getLastKnownLocation(mLocationManager.getBestProvider(mCriteria,true));
    if (lastLocation != null) {
      sLat=lastLocation.getLatitude();
      sLng=lastLocation.getLongitude();
      sAccuracy=lastLocation.getAccuracy();
      sTime=lastLocation.getTime();
    }
  }
 catch (  IllegalArgumentException e) {
    requestLocationSettings(context);
  }
}
 

Example 18

From project BART, under directory /src/pro/dbro/bart/.

Source file: DeviceLocation.java

  21 
vote

@Override public void run(){
  lm.removeUpdates(locationListenerGps);
  lm.removeUpdates(locationListenerNetwork);
  Location net_loc=null, gps_loc=null;
  if (gps_enabled)   gps_loc=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
  if (network_enabled)   net_loc=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  if (gps_loc != null && net_loc != null) {
    if (gps_loc.getTime() > net_loc.getTime())     locationResult.gotLocation(gps_loc);
 else     locationResult.gotLocation(net_loc);
    return;
  }
  if (gps_loc != null) {
    locationResult.gotLocation(gps_loc);
    return;
  }
  if (net_loc != null) {
    locationResult.gotLocation(net_loc);
    return;
  }
  locationResult.gotLocation(null);
}
 

Example 19

From project be.norio.twunch.android, under directory /src/be/norio/twunch/android/ui/.

Source file: TwunchListActivity.java

  21 
vote

@Override protected Void doInBackground(Location... locations){
  if (locations[0] == null) {
    return null;
  }
  Cursor c=getContentResolver().query(Twunches.CONTENT_URI,TwunchesQuery.PROJECTION,null,null,null);
  if (!c.moveToFirst()) {
    c.close();
    return null;
  }
  final ArrayList<ContentProviderOperation> batch=Lists.newArrayList();
  do {
    ContentProviderOperation.Builder builder=ContentProviderOperation.newUpdate(Twunches.CONTENT_URI);
    builder.withSelection(Twunches._ID + "=?",new String[]{Long.toString(c.getLong(TwunchesQuery._ID))});
    Location twunchLocation=new Location("");
    twunchLocation.setLatitude(c.getDouble(TwunchesQuery.LATITUDE));
    twunchLocation.setLongitude(c.getDouble(TwunchesQuery.LONGITUDE));
    builder.withValue(Twunches.DISTANCE,(int)locations[0].distanceTo(twunchLocation));
    batch.add(builder.build());
  }
 while (c.moveToNext());
  c.close();
  try {
    getContentResolver().applyBatch(TwunchContract.CONTENT_AUTHORITY,batch);
  }
 catch (  RemoteException e) {
    e.printStackTrace();
  }
catch (  OperationApplicationException e) {
    e.printStackTrace();
  }
  return null;
}
 

Example 20

From project beintoo-android-sdk, under directory /BeintooSDK/src/com/beintoo/activities/marketplace/.

Source file: Marketplace.java

  21 
vote

private String getSavedPlayerLocationParams(String url){
  try {
    Location loc=LocationMManager.getSavedPlayerLocation(getContext());
    if (loc != null) {
      Double latitude=loc.getLatitude();
      Double longitude=loc.getLongitude();
      Float accuracy=loc.getAccuracy();
      Uri.Builder b=Uri.parse(url).buildUpon();
      b.appendQueryParameter("lat",latitude.toString());
      b.appendQueryParameter("lng",longitude.toString());
      b.appendQueryParameter("acc",accuracy.toString());
      return b.toString();
    }
 else     return url;
  }
 catch (  Exception e) {
    return url;
  }
}
 

Example 21

From project CineShowTime-Android, under directory /Libraries/CineShowTime/src/com/binomed/showtime/android/screen/main/.

Source file: CineShowTimeMainActivity.java

  21 
vote

@Override protected void onPostRestoreBundle(Bundle savedInstanceState){
  if (savedInstanceState != null) {
    boolean saved=savedInstanceState.getBoolean(ParamIntent.BUNDLE_SAVE,false);
    if (saved) {
      getModelActivity().setLastRequestCity(savedInstanceState.getString(ParamIntent.ACTIVITY_SEARCH_CITY));
      getModelActivity().setLastRequestMovie(savedInstanceState.getString(ParamIntent.ACTIVITY_SEARCH_MOVIE_NAME));
      getModelActivity().setDay(savedInstanceState.getInt(ParamIntent.ACTIVITY_SEARCH_DAY,0));
      double latitude=savedInstanceState.getDouble(ParamIntent.ACTIVITY_SEARCH_LATITUDE,0);
      double longitude=savedInstanceState.getDouble(ParamIntent.ACTIVITY_SEARCH_LONGITUDE,0);
      if ((latitude != 0) && (longitude != 0)) {
        Location location=new Location("GPS");
        location.setLatitude(latitude);
        location.setLongitude(longitude);
        getModelActivity().setLocalisation(location);
      }
      Log.i(TAG,"Latitude : " + latitude);
      Log.i(TAG,"Longitude : " + longitude);
      fragmentSearch.refreshAfterSavedBundle();
    }
  }
}
 

Example 22

From project com.juick.android, under directory /src/com/juick/android/.

Source file: PickPlaceActivity.java

  21 
vote

@Override protected void onActivityResult(int requestCode,int resultCode,Intent data){
  if (requestCode == ACTIVITY_NEWPLACE) {
    if (resultCode == RESULT_OK) {
      setResult(RESULT_OK,data);
    }
    finish();
  }
 else   if (requestCode == ACTIVITY_PICKLOCATION && resultCode == RESULT_OK) {
    progressDialog=ProgressDialog.show(this,"",getResources().getString(R.string.Please_wait___),true,true,this);
    Location loc=new Location(LocationManager.GPS_PROVIDER);
    loc.setLatitude(data.getDoubleExtra("lat",0));
    loc.setLongitude(data.getDoubleExtra("lon",0));
    loc.setAccuracy(3000);
    onLocationChanged(loc);
  }
}
 

Example 23

From project cw-android, under directory /Service/WeatherAPI/src/com/commonsware/android/weather/.

Source file: WeatherBinder.java

  21 
vote

@Override protected ArrayList<Forecast> doInBackground(Location... locs){
  DefaultHttpClient client=new DefaultHttpClient();
  ArrayList<Forecast> result=null;
  try {
    Location loc=locs[0];
    String url=String.format(format,loc.getLatitude(),loc.getLongitude());
    HttpGet getMethod=new HttpGet(url);
    ResponseHandler<String> responseHandler=new BasicResponseHandler();
    String responseBody=client.execute(getMethod,responseHandler);
    result=buildForecasts(responseBody);
  }
 catch (  Exception e) {
    this.e=e;
  }
  client.getConnectionManager().shutdown();
  return (result);
}
 

Example 24

From project dungbeetle, under directory /src/edu/stanford/mobisocial/dungbeetle/util/.

Source file: MyLocation.java

  21 
vote

public boolean getLocation(Context context,LocationResult result){
  locationResult=result;
  if (lm == null)   lm=(LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
  try {
    gps_enabled=lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
  }
 catch (  Exception ex) {
  }
  try {
    network_enabled=lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
  }
 catch (  Exception ex) {
  }
  if (!gps_enabled && !network_enabled) {
    Toast.makeText(context,"No location provider available, defaulting to Gates Building, Stanford Univesity.",Toast.LENGTH_SHORT).show();
    Location l=new Location("yo' mama");
    l.setLongitude(-122.179727);
    l.setLatitude(37.426762);
    locationResult.gotLocation(l);
    return false;
  }
  if (gps_enabled)   lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListenerGps);
  if (network_enabled)   lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,locationListenerNetwork);
  timer1=new Timer();
  timer1.schedule(new GetLastLocation(),20000);
  return true;
}
 

Example 25

From project evodroid, under directory /src/com/sonorth/evodroid/util/.

Source file: LocationHelper.java

  21 
vote

@Override public void run(){
  lm.removeUpdates(locationListenerGps);
  lm.removeUpdates(locationListenerNetwork);
  Location net_loc=null, gps_loc=null;
  if (gps_enabled)   gps_loc=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  if (network_enabled)   net_loc=lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
  if (gps_loc != null && net_loc != null) {
    if (gps_loc.getTime() > net_loc.getTime())     locationResult.gotLocation(gps_loc);
 else     locationResult.gotLocation(net_loc);
    return;
  }
  if (gps_loc != null) {
    locationResult.gotLocation(gps_loc);
    return;
  }
  if (net_loc != null) {
    locationResult.gotLocation(net_loc);
    return;
  }
  locationResult.gotLocation(null);
}
 

Example 26

From project FlickrCity, under directory /src/com/FlickrCity/FlickrCityAndroid/Activities/.

Source file: MapViewerActivity.java

  21 
vote

@Override protected City doInBackground(Object... params){
  LocationManager locationManager=(LocationManager)params[0];
  String bestProvider=(String)params[1];
  Geocoder gcd=(Geocoder)params[2];
  Location currentLocation=locationManager.getLastKnownLocation(bestProvider);
  List<Address> currentAddress=null;
  try {
    currentAddress=gcd.getFromLocation(currentLocation.getLatitude(),currentLocation.getLongitude(),1);
  }
 catch (  IOException e) {
  }
  String cityName="";
  if (currentAddress != null && currentAddress.size() > 0)   cityName=currentAddress.get(0).getLocality();
  City currentCity=new City();
  currentCity.setName(cityName);
  currentCity.setLatitude(currentLocation.getLatitude());
  currentCity.setLongitude(currentLocation.getLongitude());
  return currentCity;
}
 

Example 27

From project friendica-for-android, under directory /mw-android-friendica-01/src/de/wikilab/android/friendica01/.

Source file: WritePostFragment.java

  21 
vote

@Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
  myView=inflater.inflate(R.layout.writepostinner,container,false);
  viewLatLon=(TextView)myView.findViewById(R.id.viewLatLon);
  sendBtn=(Button)myView.findViewById(R.id.btn_upload);
  sendBtn.setOnClickListener(new OnClickListener(){
    @Override public void onClick(    View v){
      sendMessage();
    }
  }
);
  ToggleButton sendLatLon=(ToggleButton)myView.findViewById(R.id.sendLatLon);
  sendLatLon.setOnCheckedChangeListener(new OnCheckedChangeListener(){
    @Override public void onCheckedChanged(    CompoundButton buttonView,    boolean isChecked){
      if (isChecked) {
        if (!locationListenerAttached) {
          LocationManager lm=(LocationManager)getActivity().getSystemService(Context.LOCATION_SERVICE);
          Location location=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
          lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);
          viewLatLon.setText(getString(R.string.viewLatLon) + "\n" + "Loading...");
          locationListenerAttached=true;
        }
      }
 else {
        detachLocationListener();
      }
    }
  }
);
  return myView;
}
 

Example 28

From project gast-lib, under directory /app/src/root/gast/playground/location/.

Source file: ProximityAlertService.java

  21 
vote

@Override public int onStartCommand(Intent intent,int flags,int startId){
  Location bestLocation=null;
  latitude=intent.getDoubleExtra(LATITUDE_INTENT_KEY,Double.MIN_VALUE);
  longitude=intent.getDoubleExtra(LONGITUDE_INTENT_KEY,Double.MIN_VALUE);
  radius=intent.getFloatExtra(RADIUS_INTENT_KEY,Float.MIN_VALUE);
  for (  String provider : locationManager.getProviders(false)) {
    Location location=locationManager.getLastKnownLocation(provider);
    if (bestLocation == null) {
      bestLocation=location;
    }
 else {
      if (location.getAccuracy() < bestLocation.getAccuracy()) {
        bestLocation=location;
      }
    }
  }
  if (bestLocation != null) {
    if (getDistance(bestLocation) <= radius) {
      inProximity=true;
    }
 else {
      inProximity=false;
    }
  }
  locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,this);
  return START_STICKY;
}
 

Example 29

From project google-voice-tasker-plugin, under directory /tests/src/com/yourcompany/yoursetting/test/.

Source file: BundleTestHelper.java

  21 
vote

/** 
 * Tests that parcelable objects are detected by the bundle checking mechanism.
 */
@SmallTest public void testParcelable(){
  final Bundle bundle=new Bundle();
  bundle.putParcelable("test",new Location((String)null));
  try {
    checkBundle(bundle);
    fail();
  }
 catch (  final RuntimeException e) {
  }
}
 

Example 30

From project apps-for-android, under directory /Radar/src/com/google/android/radar/.

Source file: RadarView.java

  20 
vote

/** 
 * Called when a location provider has a new location to report
 * @see android.location.LocationListener#onLocationChanged(android.location.Location)
 */
public void onLocationChanged(Location location){
  if (!mHaveLocation) {
    mHaveLocation=true;
  }
  final long now=SystemClock.uptimeMillis();
  boolean useLocation=false;
  final String provider=location.getProvider();
  if (LocationManager.GPS_PROVIDER.equals(provider)) {
    mLastGpsFixTime=SystemClock.uptimeMillis();
    useLocation=true;
  }
 else   if (LocationManager.NETWORK_PROVIDER.equals(provider)) {
    useLocation=now - mLastGpsFixTime > RETAIN_GPS_MILLIS;
    if (mNetworkLocation == null) {
      mNetworkLocation=new Location(location);
    }
 else {
      mNetworkLocation.set(location);
    }
    mLastGpsFixTime=0L;
  }
  if (useLocation) {
    mMyLocationLat=location.getLatitude();
    mMyLocationLon=location.getLongitude();
    mDistance=GeoUtils.distanceKm(mMyLocationLat,mMyLocationLon,mTargetLat,mTargetLon);
    mBearing=GeoUtils.bearing(mMyLocationLat,mMyLocationLon,mTargetLat,mTargetLon);
    updateDistance(mDistance);
  }
}
 

Example 31

From project AlarmApp-Android, under directory /src/org/alarmapp/services/position/.

Source file: SimpleSelectionStrategy.java

  19 
vote

public boolean isPositionRelevant(Location location){
  Date now=new Date();
  long ageInMs=now.getTime() - location.getTime();
  if (ageInMs > 2 * 60 * 1000) {
    return false;
  }
  return true;
}
 

Example 32

From project Alerte-voirie-android, under directory /src/com/fabernovel/alertevoirie/.

Source file: HomeActivity.java

  19 
vote

@Override public void onLocationChanged(Location location){
  if (LocationHelper.isBetterLocation(location,lastlocation)) {
    handleNewLocation(location);
    locationManager.removeUpdates(this);
    myHandler.removeCallbacks(removeUpdate);
  }
}
 

Example 33

From project AndroidCommon, under directory /src/com/asksven/android/common/location/.

Source file: GeoUtils.java

  19 
vote

public static String getNearestAddress(Context ctx,Location loc){
  if (!DataNetwork.hasDataConnection(ctx)) {
    return "";
  }
  Address address=getGeoData(ctx,loc);
  String strRet="";
  if (address != null) {
    String addr0=address.getAddressLine(0);
    String addr1=address.getAddressLine(1);
    if (!addr0.equals("")) {
      strRet=addr0;
    }
    if (!addr1.equals("")) {
      if (!strRet.equals("")) {
        strRet=strRet + ", ";
      }
      strRet=strRet + addr1;
    }
  }
  return strRet;
}
 

Example 34

From project androidtracks, under directory /src/org/sfcta/cycletracks/.

Source file: RecordingService.java

  19 
vote

@Override public void onLocationChanged(Location loc){
  if (loc != null) {
    double currentTime=System.currentTimeMillis();
    if (currentTime - latestUpdate > 999) {
      latestUpdate=currentTime;
      updateTripStats(loc);
      boolean rtn=trip.addPointNow(loc,currentTime,distanceTraveled);
      if (!rtn) {
        Log.e("FAIL","Couldn't write to DB");
      }
      notifyListeners();
    }
  }
}
 

Example 35

From project android_packages_wallpapers_basic, under directory /src/com/android/wallpaper/grass/.

Source file: GrassRS.java

  19 
vote

private void updateLocation(Location location){
  float dawn=0.3f;
  float dusk=0.75f;
  if (location != null) {
    final String timeZone=Time.getCurrentTimezone();
    final SunCalculator calculator=new SunCalculator(location,timeZone);
    final Calendar now=Calendar.getInstance();
    final double sunrise=calculator.computeSunriseTime(SunCalculator.ZENITH_CIVIL,now);
    dawn=SunCalculator.timeToDayFraction(sunrise);
    final double sunset=calculator.computeSunsetTime(SunCalculator.ZENITH_CIVIL,now);
    dusk=SunCalculator.timeToDayFraction(sunset);
  }
  mScript.set_gDawn(dawn);
  mScript.set_gDusk(dusk);
  mScript.set_gMorning(dawn + 1.0f / 12.0f);
  mScript.set_gAfternoon(dusk - 1.0f / 12.0f);
}
 

Example 36

From project CheckIn4Me, under directory /src/com/davidivins/checkin4me/activities/.

Source file: NearbyPlaces.java

  19 
vote

/** 
 * onLocationChanged
 * @param location
 */
public void onLocationChanged(Location location){
  killTimeouts();
  Ad.setLocation(location);
  ((LocationManager)getSystemService(Context.LOCATION_SERVICE)).removeUpdates(this);
  startProgressDialog("Retrieving Locations...");
  current_longitude=Double.toString(location.getLongitude());
  current_latitude=Double.toString(location.getLatitude());
  SharedPreferences persistent_storage=PreferenceManager.getDefaultSharedPreferences(this);
  Editor persistent_storage_editor=persistent_storage.edit();
  persistent_storage_editor.putString("current_longitude",current_longitude);
  persistent_storage_editor.putString("current_latitude",current_latitude);
  persistent_storage_editor.commit();
  locations_retriever=new LocationsRetriever(this,this,current_query,current_longitude,current_latitude,persistent_storage);
  locations_retriever.execute();
}
 

Example 37

From project CHMI, under directory /src/org/kaldax/app/chmi/.

Source file: CHMI.java

  19 
vote

public void onLocationChanged(Location loc){
  location=loc;
  if (loc != null) {
    bPositionFresh=true;
    chmiConfigBundle._longitude=(float)loc.getLongitude();
    chmiConfigBundle._latitude=(float)loc.getLatitude();
    latestPositionTime=new Date();
    chmiConfigBundle._position_time=latestPositionTime.getTime();
  }
  layoutProvider.recomputeCrossCoordinates();
}
 

Example 38

From project DigitbooksExamples, under directory /DigitbooksExamples/src/fr/digitbooks/android/examples/chapitre11/.

Source file: LocationActivity.java

  19 
vote

public void onLocationChanged(Location location){
  if (Config.INFO_LOGS_ENABLED) {
    Log.i(LOG_TAG,"New location received: (" + location.getLatitude() + ", "+ location.getLongitude()+ ")");
  }
  if (mStartLocation != null) {
    final double startLatitude=mStartLocation.getLatitude();
    final double startLongitude=mStartLocation.getLongitude();
    final double endLatitude=location.getLatitude();
    final double endLongitude=location.getLongitude();
    Location.distanceBetween(startLatitude,startLongitude,endLatitude,endLongitude,RESULTS);
    final String text=getResources().getString(R.string.distance_hud_text_format,endLatitude,endLongitude,RESULTS[0]);
    mDistanceText.setText(text);
    int red=(int)(255 - Math.min(RESULTS[0],DISTANCE_LIMIT) * 255 / DISTANCE_LIMIT);
    mDistanceImage.setBackgroundColor(Color.rgb(red,0,0));
  }
 else {
    mLocation=location;
    mStartButton.setEnabled(true);
  }
}
 

Example 39

From project facebook-android-sdk, under directory /examples/Hackbook/src/com/facebook/android/.

Source file: Places.java

  19 
vote

@Override public void onLocationChanged(Location loc){
  dialog.dismiss();
  if (loc != null) {
    try {
      location.put("latitude",new Double(loc.getLatitude()));
      location.put("longitude",new Double(loc.getLongitude()));
    }
 catch (    JSONException e) {
    }
    showToast("Location acquired: " + String.valueOf(loc.getLatitude()) + " "+ String.valueOf(loc.getLongitude()));
    lm.removeUpdates(this);
    fetchPlaces();
  }
}
 

Example 40

From project gpslogger, under directory /GPSLogger/src/com/mendhak/gpslogger/common/.

Source file: OpenGTSClient.java

  19 
vote

/** 
 * Send locations sing HTTP GET request to the server <p/> See <a href="http://opengts.sourceforge.net/OpenGTS_Config.pdf">OpenGTS_Config.pdf</a> section 9.1.2 Default "gprmc" Configuration
 * @param id        id of the device
 * @param locations locations
 */
public void sendHTTP(String id,Location[] locations){
  try {
    locationsCount=locations.length;
    StringBuilder url=new StringBuilder();
    url.append("http://");
    url.append(getURL());
    httpClient=new AsyncHttpClient();
    for (    Location loc : locations) {
      RequestParams params=new RequestParams();
      params.put("id",id);
      params.put("code","0xF020");
      params.put("gprmc",OpenGTSClient.GPRMCEncode(loc));
      Utilities.LogDebug("Sending URL " + url + " with params "+ params.toString());
      httpClient.get(applicationContext,url.toString(),params,new MyAsyncHttpResponseHandler(this));
    }
  }
 catch (  Exception e) {
    Utilities.LogError("OpenGTSClient.sendHTTP",e);
    OnFailure();
  }
}