Map initialization...

132 views
Skip to first unread message

Kurteknikk

unread,
Jul 1, 2010, 8:00:49 AM7/1/10
to Google Maps JavaScript API v3
Hi,

I was reading the documentation and it specifies that the map initial
zoom & center are required in the map options.
Now my question is, that when i'm not including them its not giving me
any error, which doesn't effect me much.

But my issue is that if i'm setting & changing the initial center &
zoom its not changing on my map, its not changing at all.

Even if i use this code:

var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new
google.maps.Map(document.getElementById("map_canvas"), myOptions);


taken from: http://code.google.com/apis/maps/documentation/javascript/introduction.html

It still doesn't work... So i would like to know if there's something
wrong with it please.

Damsel

unread,
Jul 1, 2010, 8:08:48 AM7/1/10
to Google Maps JavaScript API v3
Post a link to your map, please :)

Kurt Agius

unread,
Jul 1, 2010, 12:57:00 PM7/1/10
to google-map...@googlegroups.com
Hi Damsel,

This is the history page, actually its just a page which doesn't load any data to see how the map initialization looks like.

http://spotmaster.com/kurt-geo/history.php

I'll give it a deeper look this morning because i believe its a stupid problem that i'm doing with the 'autofocus' feature. But anyway i've posted the link if you want to give it a look :)

On Thu, Jul 1, 2010 at 2:08 PM, Damsel <dav...@stlucie.k12.fl.us> wrote:
Post a link to your map, please :)

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Rossko

unread,
Jul 1, 2010, 2:06:37 PM7/1/10
to Google Maps JavaScript API v3
> This is the history page, actually its just a page which doesn't load any
> data to see how the map initialization looks like.
>
> http://spotmaster.com/kurt-geo/history.php

What doesn't happen, that you were expecting?

You have a <script> element outside of the <head> or <body> sections,
that's bad.

Kurt Agius

unread,
Jul 2, 2010, 9:33:54 AM7/2/10
to google-map...@googlegroups.com
Re: script tag outside the head & body section, i know about it, its because i need to load the body first and then do the resize of the divs. But that's a small thing which can be fixed quickly.

I'm expecting that the map center & zoom level are according to the ones i specified when initializing the map.


--

Rossko

unread,
Jul 2, 2010, 5:04:24 PM7/2/10
to Google Maps JavaScript API v3
You're defining a function structure() twice, once in history.php and
once in gg_demo.js. Which one gets run will be browser dependant.

> I'm expecting that the map center & zoom level are according to the ones i
> specified when initializing the map.

In the current code, Main() is called inline.
This in turn calls RenderMap() which includes
var latlng = new google.maps.LatLng(0, 0);
var myOptions = {
zoom: 1,
center: latlng, ...
so 0,0 is used when first creating the map.

Main() then goes on to call structure(), and in FF2 at least it runs
the one in history.php
A map 'resize' event is triggered, so your listener sets a 'resize'
variable true.

Eventually, a map 'idle' event is triggered, and as 'resize' is true
focusMap() is called by the listener.
An empty LatLngBounds object is created.
Various self-referencing operations are carried out the indeterminate
bounds, with an end result of bounds that are pretty arbritary.
Then map.fitBounds is called on the arbritary object.

So the map is centred and zoomed at some arbritary place, not of your
selection.

Kurt Agius

unread,
Jul 5, 2010, 3:21:27 AM7/5/10
to google-map...@googlegroups.com
Yes you're right cause i've been working on another version and changing things around... Sorry for that.
Anyway you are right because i realized that my fitbounds was the problem because if i just zoom the map at some place (without markers) and i fitbounds again manually it will go to the same place, so thats the problem. Now i'm trying to check if there are markers, if not i won't fit bounds... And that works fine on initialization, i get the world's map showing at zoom level 1 as i want it.

The only problem i'm having is that when i get the updates in the 'live' page it doesn't zoom to fit automatically but i believe its just some small bug somewhere...


--
Reply all
Reply to author
Forward
0 new messages