我有许多地理数据在线存储着纬度和经度,我想使用distanceTo方法代替我自己的hasrsine公式。

因此,我需要将每个记录放入“位置”字段中,但这是我的问题:它需要一个“ provider”字符串。为什么? Android将如何处理这些信息?

    for (ArrayList<String> item : Places_Data) {
        Location itemloc = new Location("provider");
        itemloc.setLatitude(latIn);
        itemloc.setLongitude(lonIn);
        //do something with my new location
    }

最佳答案

Location的源代码来看,它不使用字符串来做任何有意义的事情。它仅使用它在内部描述Location。如果您执行Location#toString(),它将打印出坐标,提供者和其他详细信息(准确性等)。这就是内部描述的全部内容。

您可以使提供者成为任何东西,如以下答案所示:Creating Android Location Object

07-24 09:47
查看更多