Hi Mark,

Thanks for the answer. But still its not working. I included the code
segment that updates the code. But still not working.
Following is the code :

        LocationManager lm = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
        LocationListener ll = new mylocationlistener();
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
ll);
        Location l =
lm.getLastKnownLocation(lm.getProvider(LOCATION_SERVICE).getName());
        Log.w("LocationTracker", "The value of Location returned by
getLastKnownLocation() is : " + l.toString());
        Log.d("Current Location", l.getLatitude() + "");
        Log.d("Current Location",l.getLongitude() + "");
        Toast.makeText(this, l.getLatitude() + "" +
l.getLongitude(),Toast.LENGTH_LONG).show();

Regards,

Prayag

On May 5, 2:20 pm, Prayag Pathak <prayag.d.pat...@gmail.com> wrote:
> Hi guys,
>
> I am trying to get the latitude and longitude of the current location.
> Let me clarify, I dont want to implement a listener that will create
> an event when the location will be changed. I am trying to create an
> app that will record the current location on a button click event.
> Following is my code :
>
> hdLocMgr = (LocationManager)
> getSystemService(Context.LOCATION_SERVICE);
> Log.w("LocationTracker", "The Location Manager is :
> "+hdLocMgr.toString());
> hdLocProvider = hdLocMgr.getBestProvider(hdCrit, true);
> location = hdLocMgr.getLastKnownLocation(hdLocProvider);
> dlat = location.getLatitude();
> dlon = location.getLongitude();
> Log.w("LocationTracker", "The value of Latitude is :
> "+dlat.toString());
>
> The code gives a RunTimeException (caused by NullPointerException as
> stated in it).
>
> Kindly help me out in that.
>
> Regards,
>
> Prayag

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to