android - LocationManager.GPS_PROVIDER return 0.0 -
what problem code. want current location gps ,but every time lat , lng 0.0 .
locationmanager=(locationmanager)this.getsystemservice(context.location_service); locationlistener=new locationlistener() { @override public void onstatuschanged(string provider, int status, bundle extras) { // todo auto-generated method stub } @override public void onproviderenabled(string provider) { // todo auto-generated method stub } @override public void onproviderdisabled(string provider) { // todo auto-generated method stub } @override public void onlocationchanged(location location) { latitude=location.getlatitude(); longitude=location.getlongitude(); currentpostion(); toast.maketext(getapplicationcontext(), latitude+"<(lat,lng)>"+longitude, toast.length_short).show(); } }; locationmanager.requestlocationupdates(locationmanager.gps_provider, 15000, 0, locationlistener);
method currentpostion draw icon on map of current position.
public void currentpostion(){ if(latitude!=0.0 && longitude!=0.0){ markeroptions options=new markeroptions(); options.position(new latlng(latitude, longitude)); options.icon(bitmapdescriptorfactory.fromresource(r.drawable.myicon)); googlemap.addmarker(options); cameraposition cameraposition = new cameraposition.builder().target(new latlng(latitude,longitude)).zoom(17).build(); googlemap.animatecamera(cameraupdatefactory.newcameraposition(cameraposition)); } }
i have permissions:
<uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="com.google.android.providers.gsf.permission.read_gservices" /> <uses-permission android:name="android.permission.write_external_storage" /> <!-- required show current location --> <uses-permission android:name="android.permission.access_coarse_location" /> <uses-permission android:name="android.permission.access_fine_location" />
result:
0.0<(lat,lng)>0.0
try changing line
latitude=location.getlatitude(); longitude=location.getlongitude();
for one
latitude = double.tostring(location.getlatitude()); longitude= double.tostring(location.getlongitude())
Comments
Post a Comment