How to find Hospital Location near by my location?

后端 未结 3 1614
独厮守ぢ
独厮守ぢ 2020-12-13 23:09

I wanna idea about \"How to find Hospital Location near by my location\" using android,How is possible?,can i use google\'s database for get latitude and longit

3条回答
  •  佛祖请我去吃肉
    2020-12-13 23:17

    Distance calculations are based on LatLong math such that:

    Distance

    This uses the ‘haversine’ formula to calculate great-circle distances between the two points – that is, the shortest distance over the earth’s surface – giving an ‘as-the-crow-flies’ distance between the points (ignoring any hills!).

    Haversine formula:

    R = earth’s radius (mean radius = 6,371km)
    Δlat = lat2− lat1
    Δlong = long2− long1
    a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
    c = 2.atan2(√a, √(1−a))
    d = R.c
    

    (Note that angles need to be in radians to pass to trig functions). JavaScript:

    var R = 6371; // km
    var dLat = (lat2-lat1).toRad();
    var dLon = (lon2-lon1).toRad(); 
    var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
            Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * 
            Math.sin(dLon/2) * Math.sin(dLon/2); 
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
    var d = R * c;
    

提交回复
热议问题