Hi Amir,
Where did you test that code? Emulator or dev phone?
> You may be missing the appropriate permissions (e.g.,
> ACCESS_FINE_LOCATION) in your AndroidManifest.xml file.
Mark is right.
Additionally, I suppose that cause of crash is null pointer exception.
>>> Double latPoint = myManager.getLastKnownLocation("gps").getLatitude
Here is.
If GPS is not working, the app doesn't have appropriate permissions or
the phone couldn't determine location, "getLastKnownLocation method"
return null.
If you test on emulator, you have to send location infomation to
emulator[adb] by DDMS.
If you test on dev phone, you would test below code.
----
Double latPoint = null;
Double lngPoint = null;
Location loc = myManager.getLastKnownLocation("gps");
if(loc != null) {
latPoint = myManager.getLastKnownLocation("gps").getLatitude();
lngPoint = myManager.getLastKnownLocation("gps").getLongitude();
} else {
Log.d("location", "location is null");
}
----
cheers,
keiji
Mark Murphy wrote:
> Amit Samel wrote:
>> Hello guys,
>> i am very much new to android platform. i am trying to implement some
>> codes from Android: A Programmer’s Guide. i have installed latest sdk
>> thats why there are some issues regarding deprecated apis. when i was
>> trying to call getCurrentLocation() i got error , that this method is
>> not supported by LocationManager.So i had replaced it by
>> getLastKnownLocation . but it got crashed. can any one knows why is
>> this happening?
>> this is my code.
>> LocationManager myManager = (LocationManager)
>> getSystemService(Context.LOCATION_SERVICE);
>> Double latPoint = myManager.getLastKnownLocation("gps").getLatitude
>> ();
>> Double lngPoint = myManager.getLastKnownLocation("gps").getLongitude
>> ();
>> thanks .
>
> You may be missing the appropriate permissions (e.g.,
> ACCESS_FINE_LOCATION) in your AndroidManifest.xml file.
>
> Note that location tracking changed fairly substantially between the M5
> SDK from this summer and the current SDK.
>
--
Keiji,
[email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---