如何连续测量距离并在android中跟踪我的路径?

时间:2015-06-14 20:58:37

标签: android google-maps

我需要连续测量距离并最终跟踪路径。如何形成应用程序?是否有谷歌地图暴露的API?

2 个答案:

答案 0 :(得分:0)

您可以使用结合lat的Google Distance Matrix API。而且很长。来自设备位置服务的数据。

答案 1 :(得分:0)

我在

下写了一段伪代码
private LocationListener locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location newLocation)
{
    if (previousLocation != null)
    {
        new googledistancematixapitask(previouslocation.getlatlong(),new location.getlatlong()).execute((Void) null);
    }
    previousLocation = newLocation;
}
public class googledistancematixapitask extends AsyncTask<Void, Void, Boolean> {

private final String mSourcelatlong;
private final String mDestinationlatlong;


Postyouridetask(String sourcelatlong, String destinationlatlong) {
    mSourcelatlong = sourcelatlong;
    mDestinationlatlong = destinationlatlong;

}
@Override
protected void onPreExecute() {
    super.onPreExecute();
}
@Override
protected String doInBackground(Void... param) {
    // Building Parameters
    /*List<NameValuePair> params = new ArrayList<NameValuePair>();

    // post album id, song id as GET parameters
    params.add(new BasicNameValuePair("name", mName));
    params.add(new BasicNameValuePair("email", mEmail));
    params.add(new BasicNameValuePair("password", mPassword));
    params.add(new BasicNameValuePair("profile", mProfile));*/
    try {
        JSONObject params = new JSONObject();
        params.put("sourcelatlong", mSourcelatlong);
        params.put("destinationlatlong", mDestinationlatlong);

        String json = jsonParser.makeHttpRequest("google distance matrix api", "POST",
                params);



        JSONObject jObj = new JSONObject(json);
        if(jObj != null){
            String data = jObj.getString("success");

        }

    } catch (JSONException e) {
        e.printStackTrace();
    }

    return distance;
}

@Override
protected void onPostExecute(final String distance) {
   totaldistance += distance;
}

@Override
protected void onCancelled() {

}

1)如果我们获得位置更新并且它执行异步任务并且仍在等待谷歌返回距离。如果第二次更新到来并在第一次更新完成之前执行asynctask。当我们计算总距离时,我们不会得到错误的结果吗?