Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose 'type' property in GoogleMapsLatLngBounds #693

Closed
ColinFrick opened this issue Oct 13, 2016 · 0 comments
Closed

Expose 'type' property in GoogleMapsLatLngBounds #693

ColinFrick opened this issue Oct 13, 2016 · 0 comments

Comments

@ColinFrick
Copy link
Contributor

The LatLngBounds class of the plugin has a property named 'type' which is used to differentiate between LatLng and LatLngBounds in animateCamera and moveCamera.

Because GoogleMapsLatLngBounds doesn't expose this property animateCamera / moveCamera fails when bounds are supplied:

10-13 10:42:36.092: W/System.err(3895): java.lang.reflect.InvocationTargetException
10-13 10:42:36.092: W/System.err(3895):     at java.lang.reflect.Method.invoke(Native Method)
10-13 10:42:36.092: W/System.err(3895):     at plugin.google.maps.MyPlugin.execute(MyPlugin.java:49)
10-13 10:42:36.092: W/System.err(3895):     at plugin.google.maps.GoogleMaps$2.run(GoogleMaps.java:259)
10-13 10:42:36.092: W/System.err(3895):     at android.os.Handler.handleCallback(Handler.java:739)
10-13 10:42:36.092: W/System.err(3895):     at android.os.Handler.dispatchMessage(Handler.java:95)
10-13 10:42:36.092: W/System.err(3895):     at android.os.Looper.loop(Looper.java:148)
10-13 10:42:36.092: W/System.err(3895):     at android.app.ActivityThread.main(ActivityThread.java:5417)
10-13 10:42:36.092: W/System.err(3895):     at java.lang.reflect.Method.invoke(Native Method)
10-13 10:42:36.092: W/System.err(3895):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
10-13 10:42:36.092: W/System.err(3895):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
10-13 10:42:36.092: W/System.err(3895): Caused by: org.json.JSONException: No value for lat
10-13 10:42:36.092: W/System.err(3895):     at org.json.JSONObject.get(JSONObject.java:389)
10-13 10:42:36.092: W/System.err(3895):     at org.json.JSONObject.getDouble(JSONObject.java:444)
10-13 10:42:36.092: W/System.err(3895):     at plugin.google.maps.PluginMap.updateCameraPosition(PluginMap.java:266)
10-13 10:42:36.092: W/System.err(3895):     at plugin.google.maps.PluginMap.animateCamera(PluginMap.java:214)
10-13 10:42:36.092: W/System.err(3895):     ... 10 more

Reason: The plugin converts the LatLngBounds to an array with southwest LatLng and northeast LatLng, but because of the missing type property it is assumed that only a LatLng is supplied, and the native plugin tries to access the (not existing) lat / lng properties:

googlemaps-cdv-plugin.js:

if (cameraPosition.target && cameraPosition.target.type === "LatLngBounds") {
    cameraPosition.target = [cameraPosition.target.southwest, cameraPosition.target.northeast];
}

PluginMap.java:

JSONObject latLng;
if ("org.json.JSONArray".equals(targetClass.getName())) {
    JSONArray points = cameraPos.getJSONArray("target");
    cameraBounds = PluginUtil.JSONArray2LatLngBounds(points);
    cameraUpdate = CameraUpdateFactory.newLatLngBounds(cameraBounds, (int)(20 * this.density));
} else {
    latLng = cameraPos.getJSONObject("target");
    builder.target(new LatLng(latLng.getDouble("lat"), latLng.getDouble("lng")));
    newPosition = builder.build();
    cameraUpdate = CameraUpdateFactory.newCameraPosition(newPosition);
}

As a test I hacked in the type property and the code animates the camera successfully.

Tested in the Android Emulator:

  • Android 6.0 (Google APIs)
  • Google Maps Latest
  • ionic-native: 2.2.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants