How does it work - requestLocationUpdates() + LocationRequest/Listener

前端 未结 2 744
慢半拍i
慢半拍i 2020-12-16 09:13

I am new Android coder and I have problem with requesting updates for my localization.

I working with tutorials from http://developer.android.com/training/location/r

2条回答
  •  温柔的废话
    2020-12-16 10:11

    You are implementing LocationListener in your activity MainActivity. The call for concurrent location updates will therefor be like this:

    mLocationClient.requestLocationUpdates(mLocationRequest, this);
    

    Be sure that the LocationListener you're implementing is from the google api, that is import this:

    import com.google.android.gms.location.LocationListener;
    

    and not this:

    import android.location.LocationListener;
    

    and it should work just fine.

    It's also important that the LocationClient really is connected before you do this. I suggest you don't call it in the onCreate or onStart methods, but in onResume. It is all explained quite well in the tutorial for Google Location Api: https://developer.android.com/training/location/index.html

提交回复
热议问题