Get the distance between two geo points

后端 未结 9 616
旧巷少年郎
旧巷少年郎 2020-11-27 09:11

I want to make an app which checks the nearest place where a user is. I can easily get the location of the user and I have already a list of places with latitude and longitu

9条回答
  •  天命终不由人
    2020-11-27 09:58

    you can get distance and time using google Map API Google Map API

    just pass downloaded JSON to this method you will get real time Distance and Time between two latlong's

    void parseJSONForDurationAndKMS(String json) throws JSONException {
    
        Log.d(TAG, "called parseJSONForDurationAndKMS");
        JSONObject jsonObject = new JSONObject(json);
        String distance;
        String duration;
        distance = jsonObject.getJSONArray("routes").getJSONObject(0).getJSONArray("legs").getJSONObject(0).getJSONObject("distance").getString("text");
        duration = jsonObject.getJSONArray("routes").getJSONObject(0).getJSONArray("legs").getJSONObject(0).getJSONObject("duration").getString("text");
    
        Log.d(TAG, "distance : " + distance);
        Log.d(TAG, "duration : " + duration);
    
        distanceBWLats.setText("Distance : " + distance + "\n" + "Duration : " + duration);
    
    
    }
    

提交回复
热议问题