How To Show Placepicker Location On A Google Map?
My app uses the google maps api and the google places api. Everything works perfectly until I search for a certain place, when I search for a place and then select it from the resu
Solution 1:
You need to use the data
Intent to get the location of the Place that the user selected, add a Marker to the map, and move the camera so that it's centered over the selected Place:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data, this);
String placeName = String.format("Place: %s", place.getName());
String placeAddress = String.format("Address: %s", place.getAddress());
LatLng toLatLng = place.getLatLng();
// Add Marker
marker = mMap.addMarker(new MarkerOptions().position(toLatLng)
.title(placeName).snippet(placeAddress)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA)));
// Move Camera to selected place
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,11));
}
}
}
Post a Comment for "How To Show Placepicker Location On A Google Map?"