Getting my current location in android using GPS -


i trying current location using gps.

given following code:

    locationmanager manager = (locationmanager)this.             getsystemservice(context.location_service);      location loc = manager.getlastknownlocation(             locationmanager.gps_provider);      loc=manager.getlastknownlocation(locationmanager.gps_provider);      double la=loc.getlatitude();     double lon=loc.getlongitude(); 

when using avd emulator defined fix coordinates, or when tested android smartphone, not work.

while in android studios trying debug emulator, stuck on loc.getlatitude. overall, @ end, got java runtimeexception shown below:

java.lang.runtimeexception: unable start activity componentinfo{com.example.social.gps/com.example.social.gps.mainactivity}: java.lang.nullpointerexception         @ android.app.activitythread.performlaunchactivity(activitythread.java:2195)         .         .         . 

i guess because loc reference null.

i have:

<uses-permission     android:name="android.permission.access_fine_location" /> <uses-permission     android:name="android.permission.access_coarse_location" /> 

in manifest.

so how can work?

have ddms prespective , send latitude , longitude manually emulator.because emulator doesn't retrieve location status


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -