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);
}
});
}
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);
}
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!");
}
}
});
}
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);
}
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);
}
}
Aggregations