5050import com .google .android .gms .location .LocationSettingsRequest ;
5151import com .google .android .gms .location .LocationSettingsResult ;
5252import com .google .android .gms .location .LocationSettingsStatusCodes ;
53+ import com .google .android .gms .maps .CameraUpdate ;
54+ import com .google .android .gms .maps .CameraUpdateFactory ;
5355import com .google .android .gms .maps .GoogleMap ;
5456import com .google .android .gms .maps .GoogleMap .InfoWindowAdapter ;
5557import com .google .android .gms .maps .GoogleMap .OnCameraChangeListener ;
@@ -129,6 +131,7 @@ private enum TEXT_STYLE_ALIGNMENTS {
129131 private GoogleApiClient googleApiClient = null ;
130132 private JSONArray _saveArgs = null ;
131133 private CallbackContext _saveCallbackContext = null ;
134+ private CameraUpdate initCameraUpdate ;
132135
133136 @ SuppressLint ("NewApi" ) @ Override
134137 public void initialize (final CordovaInterface cordova , final CordovaWebView webView ) {
@@ -534,9 +537,24 @@ public void onClick(DialogInterface dialog,int id) {
534537 if (camera .has ("bearing" )) {
535538 builder .bearing ((float ) camera .getDouble ("bearing" ));
536539 }
537- if (camera .has ("latLng" )) {
538- JSONObject latLng = camera .getJSONObject ("latLng" );
539- builder .target (new LatLng (latLng .getDouble ("lat" ), latLng .getDouble ("lng" )));
540+ if (camera .has ("target" )) {
541+ CameraPosition newPosition ;
542+ Object target = camera .get ("target" );
543+ @ SuppressWarnings ("rawtypes" )
544+ Class targetClass = target .getClass ();
545+ if ("org.json.JSONArray" .equals (targetClass .getName ())) {
546+ JSONArray points = camera .getJSONArray ("target" );
547+ LatLngBounds bounds = PluginUtil .JSONArray2LatLngBounds (points );
548+ initCameraUpdate = CameraUpdateFactory .newLatLngBounds (bounds , (int )this .density );
549+ builder .target (bounds .getCenter ());
550+
551+ } else {
552+ JSONObject latLng = camera .getJSONObject ("target" );
553+ Log .d ("GoogleMaps" , "----> " + latLng .getDouble ("lat" ));
554+ builder .target (new LatLng (latLng .getDouble ("lat" ), latLng .getDouble ("lng" )));
555+ newPosition = builder .build ();
556+ initCameraUpdate = null ; //CameraUpdateFactory.newCameraPosition(newPosition);
557+ }
540558 }
541559 if (camera .has ("tilt" )) {
542560 builder .tilt ((float ) camera .getDouble ("tilt" ));
@@ -555,6 +573,7 @@ public void onClick(DialogInterface dialog,int id) {
555573 public void onMapReady (GoogleMap googleMap ) {
556574
557575 map = googleMap ;
576+
558577 try {
559578 //controls
560579 if (params .has ("controls" )) {
@@ -593,6 +612,16 @@ public void onMapReady(GoogleMap googleMap) {
593612 GoogleMaps .this .mapDivLayoutJSON = args .getJSONObject (1 );
594613 mPluginLayout .attachMyView (mapView );
595614 GoogleMaps .this .resizeMap (args , callbackContext );
615+ } else {
616+ if (initCameraUpdate != null ) {
617+ Handler handler = new Handler ();
618+ handler .postDelayed (new Runnable () {
619+ @ Override
620+ public void run () {
621+ map .moveCamera (initCameraUpdate );
622+ }
623+ }, 500 );
624+ }
596625 }
597626 callbackContext .success ();
598627 } catch (Exception e ) {
@@ -762,6 +791,15 @@ private void showDialog(final JSONArray args, final CallbackContext callbackCont
762791 private void resizeMap (JSONArray args , CallbackContext callbackContext ) throws JSONException {
763792 if (mPluginLayout == null ) {
764793 callbackContext .success ();
794+ if (initCameraUpdate != null ) {
795+ Handler handler = new Handler ();
796+ handler .postDelayed (new Runnable () {
797+ @ Override
798+ public void run () {
799+ map .moveCamera (initCameraUpdate );
800+ }
801+ }, 100 );
802+ }
765803 return ;
766804 }
767805 mapDivLayoutJSON = args .getJSONObject (args .length () - 2 );
@@ -771,6 +809,15 @@ private void resizeMap(JSONArray args, CallbackContext callbackContext) throws J
771809 float divW , divH , divLeft , divTop ;
772810 if (mPluginLayout == null ) {
773811 this .sendNoResult (callbackContext );
812+ if (initCameraUpdate != null ) {
813+ Handler handler = new Handler ();
814+ handler .postDelayed (new Runnable () {
815+ @ Override
816+ public void run () {
817+ map .moveCamera (initCameraUpdate );
818+ }
819+ }, 100 );
820+ }
774821 return ;
775822 }
776823 this .mPluginLayout .clearHTMLElement ();
@@ -792,6 +839,15 @@ private void resizeMap(JSONArray args, CallbackContext callbackContext) throws J
792839 }
793840 //mPluginLayout.inValidate();
794841 updateMapViewLayout ();
842+ if (initCameraUpdate != null ) {
843+ Handler handler = new Handler ();
844+ handler .postDelayed (new Runnable () {
845+ @ Override
846+ public void run () {
847+ map .moveCamera (initCameraUpdate );
848+ }
849+ }, 100 );
850+ }
795851 this .sendNoResult (callbackContext );
796852 }
797853
0 commit comments