← Back to team overview

phpdevshell team mailing list archive

Re: [Question #233934]: problem when loading google map

 

Question #233934 on PHPDevShell changed:
https://answers.launchpad.net/phpdevshell/+question/233934

    Status: Open => Answered

Greg proposed the following answer:
Hi

You should never use things like:

function initialize() { .. }
window.onload = initialize;

for two reasons:
- first another plugin may also declare a initialize() function
- second because window.onload is a single value, therefore you're erase any previous value

To write clean code, you must:
- use more specific function name, such as MYPROJECT_initialize() (or even better shield your code, but it may be hard to understand if you don't master javascript)
- use an event to trigger your init code

So, in your case:

- rename your init function:
function MYPROJECT_initialize() {
 map = new google.maps.Map(document.getElementById("map_canvas"), {
...
}

- trigger it with:

$(document).ready(function() {
    MYPROJECT_initialize();
}

-- 
You received this question notification because you are a member of
PHPDevShell, which is an answer contact for PHPDevShell.