Search in sources :

Example 16 with JSObject

use of com.getcapacitor.JSObject in project google-maps by capacitor-community.

the class CapacitorGoogleMaps method addMarker.

@PluginMethod()
public void addMarker(final PluginCall call) {
    final Double latitude = call.getDouble("latitude", 0d);
    final Double longitude = call.getDouble("longitude", 0d);
    final Float opacity = call.getFloat("opacity", 1.0f);
    final String title = call.getString("title", "");
    final String snippet = call.getString("snippet", "");
    final Boolean isFlat = call.getBoolean("isFlat", true);
    final JSObject metadata = call.getObject("metadata");
    final String url = call.getString("iconUrl", "");
    final Boolean draggable = call.getBoolean("draggable", false);
    if (googleMap == null) {
        call.reject("Map is not ready");
        return;
    }
    Bitmap imageBitmap = getBitmapFromURL(url);
    getBridge().getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            LatLng latLng = new LatLng(latitude, longitude);
            MarkerOptions markerOptions = new MarkerOptions();
            markerOptions.position(latLng);
            markerOptions.alpha(opacity);
            markerOptions.title(title);
            markerOptions.snippet(snippet);
            markerOptions.flat(isFlat);
            markerOptions.draggable(draggable);
            if (imageBitmap != null) {
                markerOptions.icon(BitmapDescriptorFactory.fromBitmap(imageBitmap));
            }
            Marker marker = googleMap.addMarker(markerOptions);
            // set metadata to marker
            marker.setTag(metadata);
            // get auto-generated id of the just added marker,
            // put this marker into a hashmap with the corresponding id,
            // so we can retrieve the marker by id later on
            mHashMap.put(marker.getId(), marker);
            // initialize JSObject to return when resolving this call
            JSObject result = new JSObject();
            JSObject markerResult = new JSObject();
            // get marker specific values
            markerResult.put("id", marker.getId());
            result.put("marker", markerResult);
            call.resolve(result);
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) MarkerOptions(com.google.android.libraries.maps.model.MarkerOptions) JSObject(com.getcapacitor.JSObject) LatLng(com.google.android.libraries.maps.model.LatLng) Marker(com.google.android.libraries.maps.model.Marker) PluginMethod(com.getcapacitor.PluginMethod)

Example 17 with JSObject

use of com.getcapacitor.JSObject in project google-maps by capacitor-community.

the class CapacitorGoogleMaps method onPoiClick.

public void onPoiClick(PointOfInterest pointOfInterest) {
    JSObject result = new JSObject();
    JSObject location = new JSObject();
    JSObject coordinates = new JSObject();
    coordinates.put("latitude", pointOfInterest.latLng.latitude);
    coordinates.put("longitude", pointOfInterest.latLng.longitude);
    location.put("coordinates", coordinates);
    result.put("name", pointOfInterest.name);
    result.put("placeID", pointOfInterest.placeId);
    result.put("result", location);
    notifyListeners("didTapPOIWithPlaceID", result);
}
Also used : JSObject(com.getcapacitor.JSObject)

Example 18 with JSObject

use of com.getcapacitor.JSObject in project google-maps by capacitor-community.

the class CapacitorGoogleMaps method reverseGeocodeCoordinate.

@PluginMethod()
public void reverseGeocodeCoordinate(final PluginCall call) {
    final Double latitude = call.getDouble("latitude", 0.0);
    final Double longitude = call.getDouble("longitude", 0.0);
    getBridge().executeOnMainThread(new Runnable() {

        @Override
        public void run() {
            /*
                 * TODO: Check if can be done without adding Places SDK
                 *
                 */
            Geocoder geocoder = new Geocoder(getContext());
            try {
                List<Address> addressList = geocoder.getFromLocation(latitude, longitude, 5);
                JSObject results = new JSObject();
                int index = 0;
                for (Address address : addressList) {
                    JSObject addressObject = new JSObject();
                    addressObject.put("administrativeArea", address.getAdminArea());
                    addressObject.put("lines", address.getAddressLine(0));
                    addressObject.put("country", address.getCountryName());
                    addressObject.put("locality", address.getLocality());
                    addressObject.put("subLocality", address.getSubLocality());
                    addressObject.put("thoroughFare", address.getThoroughfare());
                    results.put(String.valueOf(index++), addressObject);
                }
                call.resolve(results);
            } catch (IOException e) {
                call.error("Error in Geocode!");
            }
        }
    });
}
Also used : Address(android.location.Address) JSObject(com.getcapacitor.JSObject) List(java.util.List) IOException(java.io.IOException) Geocoder(android.location.Geocoder) PluginMethod(com.getcapacitor.PluginMethod)

Example 19 with JSObject

use of com.getcapacitor.JSObject in project google-maps by capacitor-community.

the class CapacitorGoogleMaps method onMapClick.

public void onMapClick(LatLng latLng) {
    JSObject result = new JSObject();
    JSObject location = new JSObject();
    JSObject coordinates = new JSObject();
    coordinates.put("latitude", latLng.latitude);
    coordinates.put("longitude", latLng.longitude);
    location.put("coordinates", coordinates);
    result.put("result", location);
    notifyListeners("didTapAt", result);
}
Also used : JSObject(com.getcapacitor.JSObject)

Example 20 with JSObject

use of com.getcapacitor.JSObject in project capacitor-file-picker by robingenz.

the class FilePickerPlugin method pickFilesResult.

@ActivityCallback
private void pickFilesResult(PluginCall call, ActivityResult result) {
    if (call == null) {
        return;
    }
    boolean readData = call.getBoolean("readData", true);
    int resultCode = result.getResultCode();
    switch(resultCode) {
        case Activity.RESULT_OK:
            JSObject callResult = createPickFilesResult(result.getData(), readData);
            call.resolve(callResult);
            break;
        case Activity.RESULT_CANCELED:
            call.reject(ERROR_PICK_FILE_CANCELED);
            break;
        default:
            call.reject(ERROR_PICK_FILE_FAILED);
    }
}
Also used : JSObject(com.getcapacitor.JSObject) ActivityCallback(com.getcapacitor.annotation.ActivityCallback)

Aggregations

JSObject (com.getcapacitor.JSObject)169 PluginMethod (com.getcapacitor.PluginMethod)93 JSONException (org.json.JSONException)28 JSONObject (org.json.JSONObject)20 MyRunnable (com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable)16 JSArray (com.getcapacitor.JSArray)14 Radar (io.radar.sdk.Radar)12 Uri (android.net.Uri)11 Location (android.location.Location)9 JSONArray (org.json.JSONArray)7 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)6 ParseException (java.text.ParseException)5 Intent (android.content.Intent)4 FirebaseUser (com.google.firebase.auth.FirebaseUser)4 Gson (com.google.gson.Gson)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4