-2

Possible Duplicate:
What is the simplest and most robust way to get the user's current location in Android?

I am new in android.

I just want to know how can i use the MyLocation class in my Activity which is posted on this link

What is the simplest and most robust way to get the user's current location on Android?

Thank u so much in advance.

Community
  • 1
  • 1

2 Answers2

0

Just call it in your activity :

MyLocation myLocation = new MyLocation();
iSun
  • 1,714
  • 6
  • 28
  • 57
0
MyLocation myLocation = new MyLocation();
private void locationClick() {
    myLocation.getLocation(this, locationResult));
}

public LocationResult locationResult = new LocationResult(){
    @Override
    public void gotLocation(final Location location){
        //Got the location!
        });
    }
};

That code is verbatim from the answer you linked. Just create MyLocation and pass in a LocationResult callback handler. gotLocation() will be called with a Location. You can get latitude and longitude from there.

Steve Blackwell
  • 5,904
  • 32
  • 49
  • But still i am not getting how to get latitude and longitude from there. Can u please elaborate ? – user1173092 Feb 10 '12 at 05:30
  • hey there is one more My Location class which is posted by wormhit on the same post. Can u please tell me how to use this class in an activity ? – user1173092 Feb 10 '12 at 06:01
  • Did you even try to read the documentation? `Location` has a `getLatitude()` and `getLongitude()`. More work on basic Java is probably a necessary first step, but if you want to use wormhit's code, then read and over and try it. Post a different question if you really can't get it to work. – Steve Blackwell Feb 10 '12 at 16:59
  • Thanks for the reply.i read the documentation very well and i know about the methods getLongitude() and getLatitude(). The thing that i was not getting is how the location is transferring from myLocation class to my own Activity but now i got it. But still i am not able to understand the wormhit's code can u please explain how can i use it. Thank u so much. – user1173092 Feb 11 '12 at 09:50