当前位置: 首页>>代码示例>>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;未经允许,请勿转载。