use of com.google.android.libraries.maps.model.LatLng 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.google.android.libraries.maps.model.LatLng in project google-maps by capacitor-community.
the class CapacitorGoogleMaps method addPolyline.
@PluginMethod()
public void addPolyline(final PluginCall call) {
final JSArray points = call.getArray("points", new JSArray());
getBridge().executeOnMainThread(new Runnable() {
@Override
public void run() {
PolylineOptions polylineOptions = new PolylineOptions();
for (int i = 0; i < points.length(); i++) {
try {
JSONObject point = points.getJSONObject(i);
LatLng latLng = new LatLng(point.getDouble("latitude"), point.getDouble("longitude"));
polylineOptions.add(latLng);
} catch (JSONException e) {
e.printStackTrace();
}
}
googleMap.addPolyline(polylineOptions);
call.resolve();
}
});
}
use of com.google.android.libraries.maps.model.LatLng in project google-maps by capacitor-community.
the class CapacitorGoogleMaps method create.
@PluginMethod()
public void create(PluginCall call) {
final Integer width = call.getInt("width", DEFAULT_WIDTH);
final Integer height = call.getInt("height", DEFAULT_HEIGHT);
final Integer x = call.getInt("x", 0);
final Integer y = call.getInt("y", 0);
final Float zoom = call.getFloat("zoom", DEFAULT_ZOOM);
final Double latitude = call.getDouble("latitude");
final Double longitude = call.getDouble("longitude");
final boolean liteMode = call.getBoolean("enabled", false);
final CapacitorGoogleMaps ctx = this;
getBridge().getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
LatLng latLng = new LatLng(latitude, longitude);
CameraPosition cameraPosition = new CameraPosition.Builder().target(latLng).zoom(zoom).build();
GoogleMapOptions googleMapOptions = new GoogleMapOptions();
googleMapOptions.camera(cameraPosition);
googleMapOptions.liteMode(liteMode);
if (mapViewParentId != null) {
View viewToRemove = ((ViewGroup) getBridge().getWebView().getParent()).findViewById(mapViewParentId);
if (viewToRemove != null) {
((ViewGroup) getBridge().getWebView().getParent()).removeViewInLayout(viewToRemove);
}
}
FrameLayout mapViewParent = new FrameLayout(getBridge().getContext());
mapViewParentId = View.generateViewId();
mapViewParent.setId(mapViewParentId);
mapView = new MapView(getBridge().getContext(), googleMapOptions);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(getScaledPixels(width), getScaledPixels(height));
lp.topMargin = getScaledPixels(y);
lp.leftMargin = getScaledPixels(x);
mapView.setLayoutParams(lp);
mapViewParent.addView(mapView);
((ViewGroup) getBridge().getWebView().getParent()).addView(mapViewParent);
mapView.onCreate(null);
mapView.onStart();
mapView.getMapAsync(ctx);
}
});
call.resolve();
}
use of com.google.android.libraries.maps.model.LatLng in project android-places-demos by googlemaps.
the class AutocompleteTestActivity method getOrigin.
@Nullable
private LatLng getOrigin() {
String originStr = ((TextView) findViewById(R.id.autocomplete_location_origin)).getText().toString();
if (TextUtils.isEmpty(originStr)) {
return null;
}
LatLng origin = StringUtil.convertToLatLng(originStr);
if (origin == null) {
showErrorAlert(R.string.error_alert_message_invalid_origin);
return null;
}
return origin;
}
use of com.google.android.libraries.maps.model.LatLng in project android-maps-utils by googlemaps.
the class HeatmapsDemoActivity method startDemo.
@Override
protected void startDemo(boolean isRestore) {
if (!isRestore) {
getMap().moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(-25, 143), 4));
}
// Set up the spinner/dropdown list
Spinner spinner = findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.heatmaps_datasets_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new SpinnerActivity());
try {
mLists.put(getString(R.string.police_stations), new DataSet(readItems(R.raw.police), getString(R.string.police_stations_url)));
mLists.put(getString(R.string.medicare), new DataSet(readItems(R.raw.medicare), getString(R.string.medicare_url)));
} catch (JSONException e) {
Toast.makeText(this, "Problem reading list of markers.", Toast.LENGTH_LONG).show();
}
// Make the handler deal with the map
// Input: list of WeightedLatLngs, minimum and maximum zoom levels to calculate custom
// intensity from, and the map to draw the heatmap on
// radius, gradient and opacity not specified, so default are used
}
Aggregations