android - location updates through 3g -
am developing android app retrieve data every 30sec , send server, mobile internet necessary.
currently using gps want use network provider (wifi , cell tower's).
but question how android retrieve location info through wifi? if location can retrieved through wifi can retrieve through mobile internet itself?
if no why? if yes show me code snippets retrieve location update mobile internet , can approx accuracy? need below accuracy 100meters.
i followed these , got doubt http://developer.android.com/guide/topics/location/strategies.html is android application able retrieve location info connected wifi hotspot ap?
to retrieve location network_provider can use following:
locationlistener locationlistenernetwork = new locationlistener() { public void onlocationchanged(location location) { timer1.cancel(); locationresult.gotlocation(location); lm.removeupdates(this); lm.removeupdates(locationlistenergps); } public void onproviderdisabled(string provider) {} public void onproviderenabled(string provider) {} public void onstatuschanged(string provider, int status, bundle extras) {} }; locationmanager lm; if(lm==null) lm = (locationmanager) context.getsystemservice(context.location_service); this basic example, distinguish between wi-fi , 3g network first take here , before code above do:
one way of obtaining want following:
connectivitymanager conman = (connectivitymanager) getsystemservice(context.connectivity_service); state mobile = conman.getnetworkinfo(0).getstate(); state wifi = conman.getnetworkinfo(1).getstate(); after that, distinguish them by:
if (mobile == networkinfo.state.connected || mobile == networkinfo.state.connecting) { //mobile } else if (wifi == networkinfo.state.connected || wifi == networkinfo.state.connecting) { //wifi } check, if mobile or wifi connected, if wifi - use passive_provider, if mobile - use network_provider.
i hope of information useful you.
Comments
Post a Comment