MyLocationOverlay or LocationManager for updating current location

ⅰ亾dé卋堺 提交于 2019-12-04 05:20:37
Pierry

I using Little Fluffy Location - Its a library, you setting time for updates or distance, this library make a broadcast receiver, implements LocationListener, n notify your application when location changes.

Simple, fast, easy!

Please refer this link:

After location changed, update your overlay on the map! =)

if you need, i send my full solution for locations.

Pierry

Using Little Fluffy Location 1º:

in Manifest:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.location" android:required="true" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>


<Application...>
<service android:name="com.littlefluffytoys.littlefluffylocationlibrary.LocationBroadcastService" />

    <receiver android:name="com.littlefluffytoys.littlefluffylocationlibrary.StartupBroadcastReceiver" android:exported="true">
      <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />  
      </intent-filter>  
    </receiver>
    <receiver android:name="com.littlefluffytoys.littlefluffylocationlibrary.PassiveLocationChangedReceiver" android:exported="true" />

2º Create class to extends Application

public class YourApplication extends Application {
    public void onCreate(){
        super.onCreate();
        LocationLibrary.showDebugOutput(true);
        LocationLibrary.initialiseLibrary(getBaseContext(), 0, 2 * 60 * 1000, "com.yourpackage.broadcastpackage");      
    }

    public static Context getAppContext() {
        return ApplicationVexPromoter.context;
    }
}

3º Create broadcast receiver

public class Broadcast extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
       final LocationInfo locationInfo = (LocationInfo) intent.getSerializableExtra(LocationLibraryConstants.LOCATION_BROADCAST_EXTRA_LOCATIONINFO);

    }
}

And Use:

in your activity:

public class YourActivity extends Activity {

LocationInfo info;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.id.yourview);
        info = new LocationInfo(getBaseContext());
        double latitude = info.lastLat;
        double longitude = info.lastLong;
    }
}

Need more? Please refer this

Works for me!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!