Search in sources :

Example 6 with FetchPlaceRequest

use of com.google.android.libraries.places.api.net.FetchPlaceRequest in project react-native-google-places by tolu360.

the class RNGooglePlacesModule method lookUpPlaceByID.

@ReactMethod
public void lookUpPlaceByID(String placeID, ReadableArray fields, final Promise promise) {
    this.pendingPromise = promise;
    if (!Places.isInitialized()) {
        promise.reject("E_API_KEY_ERROR", new Error("No API key defined in gradle.properties or errors initializing Places"));
        return;
    }
    List<Place.Field> selectedFields = getPlaceFields(fields.toArrayList(), false);
    FetchPlaceRequest request = FetchPlaceRequest.builder(placeID, selectedFields).build();
    placesClient.fetchPlace(request).addOnSuccessListener((response) -> {
        Place place = response.getPlace();
        WritableMap map = propertiesMapForPlace(place, selectedFields);
        promise.resolve(map);
    }).addOnFailureListener((exception) -> {
        promise.reject("E_PLACE_DETAILS_ERROR", new Error(exception.getMessage()));
    });
}
Also used : TypeFilter(com.google.android.libraries.places.api.model.TypeFilter) AutocompleteSessionToken(com.google.android.libraries.places.api.model.AutocompleteSessionToken) Arrays(java.util.Arrays) Bundle(android.os.Bundle) FindAutocompletePredictionsResponse(com.google.android.libraries.places.api.net.FindAutocompletePredictionsResponse) PackageManager(android.content.pm.PackageManager) PlaceLikelihood(com.google.android.libraries.places.api.model.PlaceLikelihood) ACCESS_FINE_LOCATION(android.Manifest.permission.ACCESS_FINE_LOCATION) FindCurrentPlaceRequest(com.google.android.libraries.places.api.net.FindCurrentPlaceRequest) PlaceSelectionListener(com.google.android.libraries.places.widget.listener.PlaceSelectionListener) FindCurrentPlaceResponse(com.google.android.libraries.places.api.net.FindCurrentPlaceResponse) WritableNativeArray(com.facebook.react.bridge.WritableNativeArray) FetchPlaceResponse(com.google.android.libraries.places.api.net.FetchPlaceResponse) Log(android.util.Log) LocationBias(com.google.android.libraries.places.api.model.LocationBias) ReadableMap(com.facebook.react.bridge.ReadableMap) LatLng(com.google.android.gms.maps.model.LatLng) FindAutocompletePredictionsRequest(com.google.android.libraries.places.api.net.FindAutocompletePredictionsRequest) ContextCompat(android.support.v4.content.ContextCompat) AutocompleteSupportFragment(com.google.android.libraries.places.widget.AutocompleteSupportFragment) Place(com.google.android.libraries.places.api.model.Place) ActivityCompat(android.support.v4.app.ActivityCompat) RequiresPermission(android.support.annotation.RequiresPermission) Objects(java.util.Objects) List(java.util.List) ReactMethod(com.facebook.react.bridge.ReactMethod) Arguments(com.facebook.react.bridge.Arguments) Nullable(android.support.annotation.Nullable) AutocompleteActivityMode(com.google.android.libraries.places.widget.model.AutocompleteActivityMode) LocationRestriction(com.google.android.libraries.places.api.model.LocationRestriction) AutocompleteActivity(com.google.android.libraries.places.widget.AutocompleteActivity) WritableArray(com.facebook.react.bridge.WritableArray) ACCESS_WIFI_STATE(android.Manifest.permission.ACCESS_WIFI_STATE) PlacesClient(com.google.android.libraries.places.api.net.PlacesClient) ReadableArray(com.facebook.react.bridge.ReadableArray) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) Intent(android.content.Intent) ActivityEventListener(com.facebook.react.bridge.ActivityEventListener) FetchPlaceRequest(com.google.android.libraries.places.api.net.FetchPlaceRequest) Task(com.google.android.gms.tasks.Task) ArrayList(java.util.ArrayList) Promise(com.facebook.react.bridge.Promise) IntentSender(android.content.IntentSender) ReactApplicationContext(com.facebook.react.bridge.ReactApplicationContext) ReactProp(com.facebook.react.uimanager.annotations.ReactProp) ReactContextBaseJavaModule(com.facebook.react.bridge.ReactContextBaseJavaModule) Places(com.google.android.libraries.places.api.Places) TextUtils(android.text.TextUtils) RectangularBounds(com.google.android.libraries.places.api.model.RectangularBounds) TimeUnit(java.util.concurrent.TimeUnit) AddressComponent(com.google.android.libraries.places.api.model.AddressComponent) Autocomplete(com.google.android.libraries.places.widget.Autocomplete) AutocompletePrediction(com.google.android.libraries.places.api.model.AutocompletePrediction) Manifest.permission(android.Manifest.permission) WritableMap(com.facebook.react.bridge.WritableMap) Status(com.google.android.gms.common.api.Status) Activity(android.app.Activity) FetchPlaceRequest(com.google.android.libraries.places.api.net.FetchPlaceRequest) WritableMap(com.facebook.react.bridge.WritableMap) Place(com.google.android.libraries.places.api.model.Place) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

FetchPlaceRequest (com.google.android.libraries.places.api.net.FetchPlaceRequest)6 Log (android.util.Log)4 Place (com.google.android.libraries.places.api.model.Place)4 PlacesClient (com.google.android.libraries.places.api.net.PlacesClient)4 List (java.util.List)4 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)3 LatLng (com.google.android.gms.maps.model.LatLng)3 FetchPlaceResponse (com.google.android.libraries.places.api.net.FetchPlaceResponse)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 ApiException (com.google.android.gms.common.api.ApiException)2 Arrays (java.util.Arrays)2 Manifest (android.Manifest)1 Manifest.permission (android.Manifest.permission)1 ACCESS_FINE_LOCATION (android.Manifest.permission.ACCESS_FINE_LOCATION)1 ACCESS_WIFI_STATE (android.Manifest.permission.ACCESS_WIFI_STATE)1 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1