Kevin Schueller
Kevin Schueller

Reputation: 77

Panning and zooming to specific coordinate in GMAP3 and JQuery

I'm trying to set use a link on the page to pan and zoom to a specific array of coordinates (where I have a marker already dropped, and gmap3 initialized). When I click the link, the Javascript fires (I get the alert), but nothing happens in my map. Please help. Here is my code:

$(".phila").click(function(){
    alert("hello");
    $("#map").gmap3({
        action:'panTo', 
        args:[39.952335, -75.163789]
    });
});

Edit: now I am getting an error in the console saying "Uncaught Error: panTo: latLng must be of type LatLng"

Upvotes: 3

Views: 4167

Answers (3)

Sydwell
Sydwell

Reputation: 5014

To zoom using gmap3 you first need to get a reference to native map object and then simply set the level.

var map = $("#map_canvas").gmap3('get');
map.setZoom(1);

Upvotes: 6

arjunaaji
arjunaaji

Reputation: 131

you may try this:

$('#test1').gmap3(
    {action:'panTo',
     args:[new google.maps.LatLng(-7,110)]}
);

it works.

Upvotes: 5

Karl Rosaen
Karl Rosaen

Reputation: 4644

Looks like the expected argument is a single point, not two separate arguments, lat, lon. try:

$("#map").gmap3({
   action:'panTo', 
     args:[[39.952335, -75.163789]]
   });
});

Upvotes: 0

Related Questions