找到android中两个位置之间的距离?

use*_*493 0 android google-maps distance

可能重复:
从我的位置到android中的目标位置的距离计算

我是Android手机谷歌地图的新手,我希望显示两个地方之间的距离.因为我写了两个autocompletedtextview我得到了来自和地点.by使用

public String host = "https://maps.googleapis.com";
public String searchPath = "/maps/api/place/autocomplete/json";
public String detailsPath = "/maps/api/place/details/json";
Run Code Online (Sandbox Code Playgroud)

我把地方名称作为字符串我想用两个字符串来计算两个地方之间的距离我怎样才能实现它在此先感谢.

ckp*_*tel 7

我认为这段代码对你有用:

double distance

Location locationA = new Location(“point A”)

locationA.setLatitude(latA)

locationA.setLongitude(lngA)

Location locationB = new Location(“point B”)

locationB.setLatitude(latB)

LocationB.setLongitude(lngB)

distance = locationA.distanceTo(locationB)
Run Code Online (Sandbox Code Playgroud)