Android Google Map V2 location update GPS? NETWORK? -
use samsung s3 , android google map v2(using "locationclient" location). functions totally normal except
indoor, first time location updated (not getlastlocation() locationmanager) very slow no updated. (gps turn on, wifi off)
indoor, turn on wifi (even did not connect hot spot) first time location updated speed fine.
i follow tutorial below , first time location update (not getlastlocation() locationmanager) speed fine if outdoor.
(google tutorial) https://developers.google.com/maps/documentation/android/location , http://developer.android.com/training/location/receive-location-updates.html
and according google here, https://developers.google.com/maps/documentation/android/start, said
android.permission.access_coarse_location allows api use wifi or mobile cell data (or both) determine device's location.
android.permission.access_fine_location allows api use global positioning system (gps) determine device's location within small area.
thus, think should location updated both network , gps.
========================
but got is
it(locationclient) seems listen gps signal if turn on gps. , if want location update network, have turn wifi on.
is correct ?
thanks...
========================
update
according google maps android api v2 creating new locationsource.
now, not use "locationclient" , set "locationsource" google map. google map can receive location updated indoor , no wifi turn on.
here use locationlistener, using same permissions you.
private void startlocationlistener() { userposition.setposition(myposition); // location manager locationmanager = (locationmanager) this.getsystemservice(context.location_service); locationlistener = new locationlistener() { public void onlocationchanged(location location) { // called when new location found network location provider. if(currlocation != null) { boolean better = isbetterlocation(location, currlocation); if(better) { currlocation.set(location); myposition = new latlng(currlocation.getlatitude(), currlocation.getlongitude()); userposition.setposition(myposition); } } else { currlocation = location; myposition = new latlng(currlocation.getlatitude(), currlocation.getlongitude()); userposition.setposition(myposition); } } public void onstatuschanged(string provider, int status, bundle extras) {} public void onproviderenabled(string provider) {} public void onproviderdisabled(string provider) {} }; locationmanager.requestlocationupdates(gpsprovider, 5000, 0, locationlistener); locationmanager.requestlocationupdates(netprovider, 30000, 0, locationlistener); } protected boolean isbetterlocation(location location, location currentbestlocation) { if (currentbestlocation == null) { // new location better no location return true; } // check whether new location fix newer or older long timedelta = location.gettime() - currentbestlocation.gettime(); boolean issignificantlynewer = timedelta > time; boolean issignificantlyolder = timedelta < -time; boolean isnewer = timedelta > 0; // if it's been more 2 minutes since current location, use new location // because user has moved if (issignificantlynewer) { return true; // if new location more 2 minutes older, must worse } else if (issignificantlyolder) { return false; } // check whether new location fix more or less accurate int accuracydelta = (int) (location.getaccuracy() - currentbestlocation.getaccuracy()); boolean islessaccurate = accuracydelta > 0; boolean ismoreaccurate = accuracydelta < 0; boolean issignificantlylessaccurate = accuracydelta > 200; // check if old , new location same provider boolean isfromsameprovider = issameprovider(location.getprovider(), currentbestlocation.getprovider()); // determine location quality using combination of timeliness , accuracy if (ismoreaccurate) { return true; } else if (isnewer && !islessaccurate) { return true; } else if (isnewer && !issignificantlylessaccurate && isfromsameprovider) { return true; } return false; }
Comments
Post a Comment