PDA

View Full Version : How to center the map?



MrNase
20 Jun 2010, 7:19 AM
Hey guys,

I am playing around with the examples and I currently try to extend the 'Guide example'.

What I want is a new button that centers the map to my current location. Just in case I scroll around and want to get back.

I created the button and that's already working but I am struggling with the rest.

Here's what I got:


var takeMeHome = function() {
var coords = map.geo.coords;
map.center(new google.maps.LatLng(coords.latitude, coords.longitude));
}


The only thing it does is that the screen flickrs when I click (touch.. ;)) the button, nothing more.


I know the Google Maps API and I now that there is a 'setCenter()' function but I already tried that with no luck.

Can someone please point me in the right direction? Thanks! :)


For some strange reason, all examples that use the Geolocation only work in Firefox (with a broken layout) and on my iPhone. Safari 5 refuses to load the map which makes debugging a little complicated.

VinylFox
20 Jun 2010, 8:51 AM
Methods in the Google API are accessed via the map property of your map panel...


var mapCenter = function(){
var pnt = new google.maps.LatLng(60, 105);
map.map.setCenter(pnt);
};

There is no center method in the map panel component.

MrNase
20 Jun 2010, 11:29 AM
Thanks, it's working now. :)

Wouldn't have thought about using map.map.[...] :-?

jamesvandyke
6 Jul 2010, 8:12 AM
This was confusing for me too. I finally set the center point in the map options setting.

Here is my code:


var pnt = new google.maps.LatLng(32.842178,-96.774654);
var mapdemo = new Ext.Map({
mapOptions:{
center: pnt,
zoom: 12,
},
});