0

The first time i write android project. And I face a problem is that. I have get the source and destination information from PlaceAutocompleteFragement. However, I don't know how to draw them in a map. I have saw some article like drawing a path in map through 2 place, but most of time is mark the point directly by clicking a place in a map instead of getting the place from textbox. Can anyone help me. Thank a lot.

Ebet
  • 21
  • 1
  • 7
  • https://www.youtube.com/watch?v=CCZPUeY94MU&t=743s skip to 24:05sec and check if thats what you want. – Aswin P Ashok Apr 19 '18 at 04:23
  • this video is similar to my idea. Can i replace textbox input of source and destination be PlaceAutocompleteFragement? @AswinPAshok – Ebet Apr 19 '18 at 07:16
  • I am not familiar with PlaceAutocompleteFragment. But if you can get the place name/LatLng of location from PlaceAutocompleteFragment, you can modify that tutorial to suit your needs. – Aswin P Ashok Apr 19 '18 at 07:28
  • `https://maps.googleapis.com/maps/api/directions/json?origin=75+9th+Ave+New+York,+NY&destination=MetLife+Stadium+1+MetLife+Stadium+Dr+East+Rutherford,+NJ+07073&key=YOUR_API_KEY` This is what google direction request url looks like. Notice **origin** and **destination** in url. If you can get Place name like that, you can get all required LatLngs along that route and plot a Polyline path. Origin an destination can also be lat-long pairs. – Aswin P Ashok Apr 19 '18 at 07:35
  • check https://developers.google.com/maps/documentation/directions/ for more on directions api – Aswin P Ashok Apr 19 '18 at 07:36

1 Answers1

0

check out this,

After initialization of google map, get your list of Latlngs between two locations and then add those Latlngs to the google map like below.

PolylineOptions options = new 
PolylineOptions().width(5).color(Color.BLUE).geodesic(true);
for (int z = 0; z < latLnglist.size(); z++) {
LatLng point = latLnglist.get(z);
options.add(point);
}
line = myMap.addPolyline(options);
hasan_shaikh
  • 1,434
  • 1
  • 15
  • 38