Making a Location object in Android with latitude and longitude values

后端 未结 3 1048
南笙
南笙 2020-12-07 16:12

I have a program in which latitude and longitude values of a location are stored in a database, which I download.

I want to get the distance between these coordinat

相关标签:
3条回答
  • 2020-12-07 16:37

    Assuming that you already have a location object with you current location.

    Location targetLocation = new Location("");//provider name is unnecessary
    targetLocation.setLatitude(0.0d);//your coords of course
    targetLocation.setLongitude(0.0d);
    
    float distanceInMeters =  targetLocation.distanceTo(myLocation);
    
    0 讨论(0)
  • 2020-12-07 16:52

    You may create locations using their constructor, then set the latutude and longitude values.

    final Location location = new Location("yourprovidername");
    location.setLatitude(1.2345d);
    location.setLongitude(1.2345d);
    
    0 讨论(0)
  • 2020-12-07 16:58

    I am answering this again, because lot of people like me do not know what "providername" actually is. Below code answers the question:

    Location location = new Location(LocationManager.GPS_PROVIDER);
    location.setLatitude(23.5678);
    location.setLongitude(34.456);
    

    Here I am using LocationManager.GPS_PROVIDER as the provider name.

    0 讨论(0)
提交回复
热议问题