當前位置: 首頁>>代碼示例>>Java>>正文


Java LocationListener.onLocationChanged方法代碼示例

本文整理匯總了Java中android.location.LocationListener.onLocationChanged方法的典型用法代碼示例。如果您正苦於以下問題:Java LocationListener.onLocationChanged方法的具體用法?Java LocationListener.onLocationChanged怎麽用?Java LocationListener.onLocationChanged使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.location.LocationListener的用法示例。


在下文中一共展示了LocationListener.onLocationChanged方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onLocationChanged

import android.location.LocationListener; //導入方法依賴的package包/類
@Override
public void onLocationChanged(Location location) {
	Log.d(Constants.LOGGING_TAG, "Location updated in GPSTracker: " + location.toString());
	 //Record location
       final UserLog log = new UserLog();
	log.setTime(new Date());
	log.setLatitude(location.getLatitude());
       log.setLongitude(location.getLongitude());
       
       User.getId(mContext, new UserIdListener(){

		@Override
		public void onUserId(Integer id) {
			log.setUserId(id);
			TanapaDbHelper.getInstance(getBaseContext()).saveLocation(log);
		}
       	
       });
	for ( LocationListener l : locationListeners ) {
		l.onLocationChanged(location);
	}
}
 
開發者ID:rpkelly,項目名稱:tanapa-safari-android,代碼行數:23,代碼來源:GPSTracker.java

示例2: onLocationChanged

import android.location.LocationListener; //導入方法依賴的package包/類
@Override
public void onLocationChanged(Location location) {
	if (location != null && location.getProvider().equals(LocationManager.GPS_PROVIDER)) {
		mLastGPSLocation = location;
	}
	if (!LocationUtils.isBetterLocation(location, mLastBestLocation)) {
		return;
	}
	mLastBestLocation = location;

	synchronized (mLockGeoObject) {
		for (int i = 0; i < mArrayListGeoObject.size(); i++) {
			mArrayListGeoObject.get(i).setLocation(location);
		}
	}
	synchronized (mLockWorld) {
		for (int i = 0; i < mArrayListWorld.size(); i++) {
			mArrayListWorld.get(i).setLocation(location);
		}
	}
	synchronized (mLockLocationListener) {
		for (LocationListener listener : mArrayLocationListener) {
			listener.onLocationChanged(mLastBestLocation);
		}
	}
}
 
開發者ID:BeyondAR,項目名稱:beyondar,代碼行數:27,代碼來源:BeyondarLocation.java

示例3: onLocationChanged

import android.location.LocationListener; //導入方法依賴的package包/類
public void onLocationChanged(Location location) {
	if (isBetterLocation(location, currentLocation)) {
		currentLocation = location;
		for (LocationListener listener: listeners) {
			listener.onLocationChanged(location);
		}
		if (googleMapListener != null) {
			googleMapListener.onLocationChanged(location);
		}
	}
}
 
開發者ID:projectkiri,項目名稱:smartpublictransport-as,代碼行數:12,代碼來源:LocationFinder.java

示例4: testBroadcastEventOnLocationChange

import android.location.LocationListener; //導入方法依賴的package包/類
@SmallTest
public void testBroadcastEventOnLocationChange() throws Exception {
    when(_mockLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)).thenReturn(true);
    when(_mockDataStore.getFirstLocationLattitude()).thenReturn(1.0f);
    when(_mockDataStore.getFirstLocationLongitude()).thenReturn(3.0f);
    long ts = 1200000000000l;
    when(_mockTime.getCurrentTimeMilliseconds()).thenReturn(ts);

    _serviceCommand.execute(_app);
    _serviceCommand.onGPSChangeState(new GPSChangeState(BaseChangeState.State.START));

    ArgumentCaptor<LocationListener> locationListenerCaptor = ArgumentCaptor.forClass(LocationListener.class);
    verify(_mockLocationManager,timeout(1000).times(1)).requestLocationUpdates(
            anyString(),
            anyLong(),
            anyFloat(),
            locationListenerCaptor.capture());

    Location location = new Location("location");
    LocationListener listenerArgument = locationListenerCaptor.getValue();
    when(_mockTime.getCurrentTimeMilliseconds()).thenReturn(ts+10000);
    listenerArgument.onLocationChanged(location);

    ArgumentCaptor<NewLocation> captor = ArgumentCaptor.forClass(NewLocation.class);
    verify(_bus,timeout(1000).atLeast(1)).post(captor.capture());

    int nb = 0;
    for (int i = 0; i < captor.getAllValues().size(); i++) {
        try {
            NewLocation newLocation = captor.getAllValues().get(i);
            nb++;
        } catch (ClassCastException e) {
            // other type
        }
    }
    assertEquals(2, nb);
    // 2: one with onGPSChangeState (saved one), one with onLocationChanged
}
 
開發者ID:team-mount-ventoux,項目名稱:JayPS-AndroidApp,代碼行數:39,代碼來源:GPSServiceCommandTest.java

示例5: publishLocationChanged

import android.location.LocationListener; //導入方法依賴的package包/類
private void publishLocationChanged(Location location) {
  mostRecentLocation = location;
  for (LocationListener listener : listeners) {
    listener.onLocationChanged(location);
  }
}
 
開發者ID:postnummeruppror,項目名稱:insamlingsappen-android,代碼行數:7,代碼來源:CompoundLocationService.java

示例6: handleMessage

import android.location.LocationListener; //導入方法依賴的package包/類
@SuppressLint("NewApi")
public void handleMessage(Message msg) {
	Log.i(TAG, "msg obj = " + String.valueOf(msg.obj));
	switch(msg.what){
	case MSG_GET_LOCATION:
		Uri uri = Uri.parse(msg.obj.toString());
		if(msg.getData() != null){
			//Intent reply = msg.getData().getParcelable(Intent.EXTRA_INTENT);
			PendingIntent replyTo = msg.getData().getParcelable(Intent.EXTRA_INTENT);
			//Log.d(TAG, "replyTo: " + String.valueOf(replyTo));
			LocationListener listener = getListener(null,uri,msg.arg1, msg.getData());
			try{
				Criteria criteria = new Criteria();
				if(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.FROYO){
					criteria.setPowerRequirement(Criteria.POWER_HIGH);
					criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
				} else {
					criteria.setAccuracy(Criteria.ACCURACY_FINE);
				}
				List<String> providers = locationManager.getProviders(criteria, true);
				for(String provider: providers){
					Log.d(TAG, "Using location provider: " + provider);
					locationManager.requestLocationUpdates(provider, 0, 0, listener);
				}
				//if(TextUtils.isEmpty(provider))
				//	throw new IllegalArgumentException("No location providers available");
				// add to our listeners so that we can clean up later if necessary
				//replies.put(msg.arg1, replyTo);
				if(providers.size() == 0){
					Location nullLocation = new Location(LocationManager.GPS_PROVIDER);
					nullLocation.setAccuracy(0);
					nullLocation.setLatitude(0);
					nullLocation.setLongitude(0);
					listener.onLocationChanged(nullLocation);
				} else {
					listeners.put(msg.arg1, listener);
				}
			} catch (Exception e){
				Log.e(TAG, "Error getting location updates: " + e.getMessage());
				e.printStackTrace();
				removeListener(msg.arg1);
			}
		} else {
			Log.w(TAG, "no replyTo in original intent sent to InstrumentationService");
			removeListener(msg.arg1);
		}
		break;
	default:
		Log.w(TAG, "Unknown message! Message = " + msg.what);
		removeListener(msg.arg1);
	}
}
 
開發者ID:SanaMobile,項目名稱:sana.mobile,代碼行數:53,代碼來源:InstrumentationService.java

示例7: addLocationListener

import android.location.LocationListener; //導入方法依賴的package包/類
/**
 * Add a new listener for this service, and call the location changed event
 * if a location is already available.
 * 
 * @param listener
 *            the listener to add.
 */
public void addLocationListener(LocationListener listener) {
	listeners.add(listener);
	if (currentLocation != null) {
		listener.onLocationChanged(currentLocation);
	}
}
 
開發者ID:projectkiri,項目名稱:smartpublictransport-as,代碼行數:14,代碼來源:LocationFinder.java


注:本文中的android.location.LocationListener.onLocationChanged方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。