cordova-plugin-googlemaps icon indicating copy to clipboard operation
cordova-plugin-googlemaps copied to clipboard

latLngBounds and setCenter with current location

Open xloading opened this issue 10 years ago • 4 comments

@wf9a5m75 thank you very much for this plugin indeed! Could anyone please advise me if it is possible with plugin's built-in API functions to define the array of markers to bound the camera view to and at the same time to set center of the camera at defined user's location. Right now I have the following picture: 2016-05-10 22 32 08

However I want blue location dot to be present in the center with marker still in up left (north west) corner meaning that I need some auto zoom-out after the bounds are set.

Does this require some custom zoom calculation logic to be coded or can be accomplished with provided map API?

Thank you in advance!

xloading avatar May 10 '16 19:05 xloading

Just for your reference here is my code (I have tried to use animateCamera(bounds) and setCenter at the same time without any results):

$cordovaGeolocation.getCurrentPosition(options).then(function (position) {

      var currentLocation = new plugin.google.maps.LatLng(position.coords.latitude, position.coords.longitude);
      var latLng = [currentLocation];

      var div = document.getElementById("map_canvas");
      var map = plugin.google.maps.Map.getMap(div, {
        'backgroundColor': 'white',
        'controls': {
          'compass': true,
          'myLocationButton': true,
          //'indoorPicker': true,
          'zoom': true
        },
        'gestures': {
          'scroll': true,
          'tilt': false,
          'rotate': true,
          'zoom': true
        },
        'camera': {
          'latLng': currentLocation,
          //'tilt': 30,
          'zoom': 14,
          //'bearing': 30
        },
        'mapType': plugin.google.maps.MapTypeId.ROADMAP
      });

      //Wait until the map is loaded
      map.addEventListener(plugin.google.maps.event.MAP_READY, function(){

        GuideCoord.query({}, function(data) {
          $rootScope.guideCoords = data;

          for (var i = 0; i < $rootScope.guideCoords.length; i++) {
            var guidePos = new plugin.google.maps.LatLng($rootScope.guideCoords[i].lat, $rootScope.guideCoords[i].lng);
            latLng.push(guidePos);

            map.addMarker({
              'position': guidePos,
              'title': "Hello GoogleMap for Cordova!"
            }, function(marker) {

              marker.showInfoWindow();

            });

          }
          latLng.push(currentLocation);
          var latLngBounds = new plugin.google.maps.LatLngBounds(latLng);

          map.animateCamera({
            'target' : latLngBounds
          });

          //map.setCenter(currentLocation);

        });

      });

      map.getMyLocation(function(location) {
        /*var msg = ["Current your location:\n",
          "latitude:" + location.latLng.lat,
          "longitude:" + location.latLng.lng,
          "speed:" + location.speed,
          "time:" + location.time,
          "bearing:" + location.bearing].join("\n");

        map.addMarker({
          'position': location.latLng,
          'title': msg
        }, function(marker) {
          marker.showInfoWindow();
        });*/
      });
    }, function (error) {
      console.log("Could not get location");
    });

xloading avatar May 10 '16 19:05 xloading

Hello @xloading! I'm not sure if you'll get an answer here because you're asking in the issues section. The plugin developers have a google+ page setup where I've asked questions like these and might be better at getting an answer to your question. Here's the link: phonegap-googlemaps-plugin. Give that a try too.

JeffreyJamesAttenti avatar May 25 '16 16:05 JeffreyJamesAttenti

@xloading did you find an answer to this question ?

I'm using this plugin in a Ionic2 beta 11 env with angular2 RC4. Here is what i see between iOS and Android builds : setCenter works fine on android but not on iOS Animate with bounds with a "fitbounds" auto-zoom doesn't seem to work.

Any ideas ?

mmazloum avatar Aug 22 '16 10:08 mmazloum

I think this issue is fixed in the v2-beta version. https://github.com/mapsplugin/v2.0-demo https://github.com/mapsplugin/cordova-plugin-googlemaps/wiki/v2-beta

wf9a5m75 avatar Nov 04 '16 16:11 wf9a5m75