re-center map button

2,305 views
Skip to first unread message

Natalie O'Toole

unread,
Sep 13, 2011, 12:43:59 PM9/13/11
to google-map...@googlegroups.com
Hi,

How do I create a re-center map button that when clicked brings the map back to the center of the map in V.3?

Please help.

Thanks,

Nat

geoco...@gmail.com

unread,
Sep 13, 2011, 12:49:46 PM9/13/11
to Google Maps JavaScript API v3
On Sep 13, 9:43 am, Natalie O'Toole <noto...@mtroyal.ca> wrote:
> Hi,
>
> How do I create a re-center map button that when clicked brings the map back
> to the center of the map in V.3?
>

What do you mean by re-center the map that when clicked brings the map
back to the center of the map?

If you mean "how do I sent the center of the map to be the same as
when the map first opens (is initialized), then you need to do that.

If you were to follow the posting guidelines and provide a link to the
map you are talking about it would help us to answer your question.

http://groups.google.com/group/google-maps-js-api-v3/browse_frm/thread/2b3f101fd509919e

-- Larry



> Please help.
>
> Thanks,
>
> Nat

Natalie O'Toole

unread,
Sep 13, 2011, 12:50:44 PM9/13/11
to google-map...@googlegroups.com

Hi,

This is my code so far:

<input type=button value="Re-center map" onClick="map.setCenter(new google.maps.LatLng(51.012645,-114.132210))"/>

Nat

Natalie O'Toole

unread,
Sep 13, 2011, 12:54:25 PM9/13/11
to google-map...@googlegroups.com
Hi,

How do I create a button that when clicked puts the map back to its original, starting position, please?
Here is the link to my google maps v.3 API app:

http://www.mtroyal.ca/MRUCampusMaps/mobilemaps2.html

Right now, this button does not work.

Please advise.

Thanks,

Nat

Rossko

unread,
Sep 13, 2011, 1:04:37 PM9/13/11
to Google Maps JavaScript API v3
> http://www.mtroyal.ca/MRUCampusMaps/mobilemaps2.html
>
> Right now, this button does not work.

Review the javascript error your browser produces when the button is
poked
'map' is undefined.

Your 'map' is only defined within your initialize() function, and
after the function has completed it is no longer available to other
functions (such as your button)
function initialize() {
...
var map = new google.maps....

Define your empty 'map' variable in global scope, and change
initialize() to create your API map using the global 'map' variable.
var map;
function initialize() {
...
map = new google.maps....

It's basic javascript, not maps magic

Natalie O'Toole

unread,
Sep 13, 2011, 1:38:59 PM9/13/11
to google-map...@googlegroups.com
That worked!

Thank-you,

Nat
Reply all
Reply to author
Forward
0 new messages