String placeAddress = String.format("Address: %s", place.getAddress()); LatLng toLatLng = place.getLatLng();
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) { if (resultCode == getActivity().RESULT_OK) { Place place = PlaceAutocomplete.getPlace(getActivity(), data); mSearchPlace = place; mSearchText.setText(String.valueOf(place.getName())); // You will get Lat,Long values here where you can use it to move your map or reverse geo code it. LatLng latLng = new LatLng(place.getLatLng().latitude, place.getLatLng().longitude); mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 12)); } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) { Status status = PlaceAutocomplete.getStatus(getActivity(), data); } else if (resultCode == getActivity().RESULT_CANCELED) { // The user canceled the operation. } } }
Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId) .setResultCallback(new ResultCallback<PlaceBuffer>() { @Override public void onResult(PlaceBuffer places) { if (places.getStatus().isSuccess() && places.getCount() > 0) { final Place myPlace = places.get(0); Log.i(TAG, "Place found: " + myPlace.getName()); LatLng latlangObj = myPlace.getLatLng(); Log.v("latitude:", "" + latlangObj.latitude); Log.v("longitude:", "" + latlangObj.longitude); } else { Log.e(TAG, "Place not found"); } places.release(); } });
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLACE_PICKER_REQUEST && resultCode == Activity.RESULT_OK) { final Place place = PlacePicker.getPlace(this, data); final CharSequence name = place.getName(); final CharSequence address = place.getAddress(); String attributions = (String) place.getAttributions(); if (attributions == null) { attributions = ""; } tv4.setText(place.getLatLng().toString()+"\n"+name+"\n"+address+"\n"+attributions); // Add this line to make the lite map show the location you just chose // and set the zoom level (10f is arbitrary) mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLng(), 10f)); } else { super.onActivityResult(requestCode, resultCode, data); } }
Double latitude, longitude; String placeName, address; protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLACE_PICKER_REQUEST) { if (resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(data, this); latitude = place.getLatLng().latitude; longitude = place.getLatLng().longitude; placeName = String.valueOf(place.getName()); address = String.valueOf(place.getAddress()); if (mMap != null) { LatLng loc2 = new LatLng(latitude, longitude); marker2 = mMap.addMarker(new MarkerOptions().position(loc2).title(placeName.toString()).visible(true)); mMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(latitude, longitude))); } } } }
String placeName = String.valueOf(place.getName()); LatLng latLong = place.getLatLng(); String lat = String.valueOf(latLong.latitude); String lon = String.valueOf(latLong.longitude);
int PLACE_PICKER_REQUEST = 1; String toastMsg; Location selectedLocation = new Location(provider); Location currentLocation = new Location(provider); double maxDistance = 10; protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PLACE_PICKER_REQUEST) { if (resultCode == RESULT_OK) { Place place = PlacePicker.getPlace(data, this); selectedLocation.setLatitude(place.getLatLng().latitude); selectedLocation.setLongitude(place.getLatLng().longitude); if(selectedLocation.distanceTo(currentLocation) > maxDistance) { toastMsg = "Invalid selection, please reselect your place"; // Runs the selector again PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder(); startActivityForResult(builder.build(this), PLACE_PICKER_REQUEST); } else { // Result is fine toastMsg = String.format("Place: %s", place.getName()); } Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show(); } } }
Log.i("coordinates", place.getLatLng().toString());
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_AUTOCOMPLETE) { if (resultCode == RESULT_OK) { // Get the user's selected place from the Intent. Place place = PlaceAutocomplete.getPlace(mActivity, data); Log.i("TAG", "Place Selected: " + place.getName()); LatLng latLng = place.getLatLng(); latitude = latLng.latitude; longitude = latLng.longitude; Log.v(ApplicationsConstants.LoginDetails.LATITUDE, "" + latitude); Log.v(ApplicationsConstants.LoginDetails.LONGITUDE, "" + longitude); tvCity.setText(place.getName()); Utils.saveDataToPreferences(mActivity, ApplicationsConstants.LoginDetails.CITY, "" + place.getName()); Utils.saveDataToPreferences(mActivity, ApplicationsConstants.LoginDetails.LATITUDE, "" + latitude); Utils.saveDataToPreferences(mActivity, ApplicationsConstants.LoginDetails.LONGITUDE, "" + longitude); } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) { Status status = PlaceAutocomplete.getStatus(mActivity, data); Log.e("TAG", "Error: Status = " + status.toString()); } else if (resultCode == RESULT_CANCELED) { // Indicates that the activity closed before a selection was made. For example if // the user pressed the back button. } } }