You have to call this method at onCreate.
private void getPath(){
float sourceLat = yourSourceLatitude;
float sourceLng = yourSourceLongitude;
float descLat = yourDescLatitude;
float descLng = yourDescLongitude;
LatLng origin = new LatLng((int)(sourceLat * 1E6), (int)(sourceLng * 1E6));
LatLng dest = new LatLng((int)(descLat * 1E6), (int)(descLng * 1E6));
// Getting URL to the Google Directions API
String url = getDirectionsUrl(origin, dest);
DownloadTask downloadTask = new DownloadTask();
// Start downloading json data from Google Directions API
downloadTask.execute(url);
}
To camera animation:
private void CamView(float descLat, float descLng)
{
CameraPosition cameraPosition = new CameraPosition.Builder().target(
new LatLng(descLat, descLng)).zoom(12).build();
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
Call this method at onPostExecute()
;
Please go through some good tutorials for google maps integration.
5
solved How to draw path for given lat long values [closed]