Search in sources :

Example 1 with RadarAddress

use of io.radar.sdk.model.RadarAddress in project capacitor-radar by radarlabs.

the class RadarPlugin method geocode.

@PluginMethod()
public void geocode(final PluginCall call) throws JSONException {
    if (!call.hasOption("query")) {
        call.reject("query is required");
        return;
    }
    String query = call.getString("query");
    Radar.geocode(query, new Radar.RadarGeocodeCallback() {

        @Override
        public void onComplete(@NotNull Radar.RadarStatus status, @Nullable RadarAddress[] addresses) {
            if (status == Radar.RadarStatus.SUCCESS && addresses != null) {
                JSObject ret = new JSObject();
                ret.put("status", status.toString());
                ret.put("addresses", RadarPlugin.jsArrayForJSONArray(RadarAddress.toJson(addresses)));
                call.resolve(ret);
            } else {
                call.reject(status.toString());
            }
        }
    });
}
Also used : Radar(io.radar.sdk.Radar) JSObject(com.getcapacitor.JSObject) RadarAddress(io.radar.sdk.model.RadarAddress) PluginMethod(com.getcapacitor.PluginMethod)

Example 2 with RadarAddress

use of io.radar.sdk.model.RadarAddress in project capacitor-radar by radarlabs.

the class RadarPlugin method autocomplete.

@PluginMethod()
public void autocomplete(final PluginCall call) throws JSONException {
    if (!call.hasOption("query")) {
        call.reject("query is required");
        return;
    }
    String query = call.getString("query");
    if (!call.hasOption("near")) {
        call.reject("near is required");
        return;
    }
    JSObject nearObj = call.getObject("near");
    double latitude = nearObj.getDouble("latitude");
    double longitude = nearObj.getDouble("longitude");
    Location near = new Location("RadarSDK");
    near.setLatitude(latitude);
    near.setLongitude(longitude);
    near.setAccuracy(5);
    int limit = call.getInt("limit", 10);
    Radar.autocomplete(query, near, limit, new Radar.RadarGeocodeCallback() {

        @Override
        public void onComplete(@NotNull Radar.RadarStatus status, @Nullable RadarAddress[] addresses) {
            if (status == Radar.RadarStatus.SUCCESS && addresses != null) {
                JSObject ret = new JSObject();
                ret.put("status", status.toString());
                ret.put("addresses", RadarPlugin.jsArrayForJSONArray(RadarAddress.toJson(addresses)));
                call.resolve(ret);
            } else {
                call.reject(status.toString());
            }
        }
    });
}
Also used : Radar(io.radar.sdk.Radar) JSObject(com.getcapacitor.JSObject) RadarAddress(io.radar.sdk.model.RadarAddress) Location(android.location.Location) PluginMethod(com.getcapacitor.PluginMethod)

Example 3 with RadarAddress

use of io.radar.sdk.model.RadarAddress in project flutter-radar by radarlabs.

the class RadarFlutterPlugin method autocomplete.

public void autocomplete(MethodCall call, final Result result) {
    String query = call.argument("query");
    HashMap nearMap = (HashMap) call.argument("near");
    Location near = locationForMap(nearMap);
    int limit = call.hasArgument("limit") ? (int) call.argument("limit") : 10;
    Radar.autocomplete(query, near, limit, new Radar.RadarGeocodeCallback() {

        @Override
        public void onComplete(final Radar.RadarStatus status, final RadarAddress[] addresses) {
            runOnMainThread(new Runnable() {

                @Override
                public void run() {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("status", status.toString());
                        if (addresses != null) {
                            obj.put("addresses", RadarAddress.toJson(addresses));
                        }
                        HashMap<String, Object> map = new Gson().fromJson(obj.toString(), HashMap.class);
                        result.success(map);
                    } catch (Exception e) {
                        result.error(e.toString(), e.getMessage(), e.getMessage());
                    }
                }
            });
        }
    });
}
Also used : HashMap(java.util.HashMap) Gson(com.google.gson.Gson) RadarAddress(io.radar.sdk.model.RadarAddress) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Radar(io.radar.sdk.Radar) JSONObject(org.json.JSONObject) Location(android.location.Location)

Example 4 with RadarAddress

use of io.radar.sdk.model.RadarAddress in project flutter-radar by radarlabs.

the class RadarFlutterPlugin method ipGeocode.

public void ipGeocode(MethodCall call, final Result result) {
    Radar.ipGeocode(new Radar.RadarIpGeocodeCallback() {

        @Override
        public void onComplete(final Radar.RadarStatus status, final RadarAddress address, final boolean proxy) {
            runOnMainThread(new Runnable() {

                @Override
                public void run() {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("status", status.toString());
                        if (address != null) {
                            obj.put("address", address.toJson());
                            obj.put("proxy", proxy);
                        }
                        HashMap<String, Object> map = new Gson().fromJson(obj.toString(), HashMap.class);
                        result.success(map);
                    } catch (Exception e) {
                        result.error(e.toString(), e.getMessage(), e.getMessage());
                    }
                }
            });
        }
    });
}
Also used : Gson(com.google.gson.Gson) RadarAddress(io.radar.sdk.model.RadarAddress) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Radar(io.radar.sdk.Radar) JSONObject(org.json.JSONObject)

Example 5 with RadarAddress

use of io.radar.sdk.model.RadarAddress in project flutter-radar by radarlabs.

the class RadarFlutterPlugin method geocode.

public void geocode(MethodCall call, final Result result) {
    String query = call.argument("query");
    Radar.geocode(query, new Radar.RadarGeocodeCallback() {

        @Override
        public void onComplete(final Radar.RadarStatus status, final RadarAddress[] addresses) {
            runOnMainThread(new Runnable() {

                @Override
                public void run() {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("status", status.toString());
                        if (addresses != null) {
                            obj.put("addresses", RadarAddress.toJson(addresses));
                        }
                        HashMap<String, Object> map = new Gson().fromJson(obj.toString(), HashMap.class);
                        result.success(map);
                    } catch (Exception e) {
                        result.error(e.toString(), e.getMessage(), e.getMessage());
                    }
                }
            });
        }
    });
}
Also used : Gson(com.google.gson.Gson) RadarAddress(io.radar.sdk.model.RadarAddress) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Radar(io.radar.sdk.Radar) JSONObject(org.json.JSONObject)

Aggregations

Radar (io.radar.sdk.Radar)5 RadarAddress (io.radar.sdk.model.RadarAddress)5 Gson (com.google.gson.Gson)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 Location (android.location.Location)2 JSObject (com.getcapacitor.JSObject)2 PluginMethod (com.getcapacitor.PluginMethod)2 HashMap (java.util.HashMap)1