problem when loading google map

Asked by joha

hi,

phpdevshell is the first framework i ever used. During the development, i encounter some issue.

Below is the code i paste into track.tpl file in views folder

{literal}
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
 map = new google.maps.Map(document.getElementById("map_canvas"), {
 center: new google.maps.LatLng(3.33, 122.333),
 zoom: 8,
 mapTypeId: google.maps.MapTypeId.ROADMAP,
 scaleControl: true,
 mapTypeControl: true,
 zoomControl: true,
    zoomControlOptions: {
      style: google.maps.ZoomControlStyle.LARGE
    },
  mapTypeControlOptions: {
 style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
 },
  streetViewControl: true,
 navigationControl: true,
 navigationControlOptions: {
 style: google.maps.NavigationControlStyle.SMALL
 }
 });
}
</script>
<script>
window.onload = initialize;
</script>
{/literal}

{$test}
<div id="map_canvas" style="width:600px;height:600px"></div>

the issue is my ggogle map toolbar is not appear in chrome and IE.

I did not encounter this issue when load into blank php page without using framework.

Thank in advance. I hope i can use this framework on my next project

Question information

Language:
English Edit question
Status:
Answered
For:
PHPDevShell Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Greg (gregfr) said :
#1

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();
}

Revision history for this message
joha (johagood) said :
#2

Dear Greg,

I have change my code according your suggestion and unfortunately, my web page doesn't display any map.

below is my code

{literal}
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function MYProject_initialize() {
 map = new google.maps.Map(document.getElementById("map_canvas"), {
 center: new google.maps.LatLng(3.33, 122.333),
 zoom: 8,
 mapTypeId: google.maps.MapTypeId.ROADMAP,
 scaleControl: true,
 mapTypeControl: true,
 zoomControl: true,
    zoomControlOptions: {
      style: google.maps.ZoomControlStyle.LARGE
    },
  mapTypeControlOptions: {
 style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
 },
  streetViewControl: true,
 navigationControl: true,
 navigationControlOptions: {
 style: google.maps.NavigationControlStyle.SMALL
 }
 });
}
</script>
<script>
$(document).ready(function() {
    MYProject_initialize();
}
</script>
{/literal}

{$test}
<div id="map_canvas" style="width:600px;height:600px"></div>

Revision history for this message
Launchpad Janitor (janitor) said :
#3

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Greg (gregfr) said :
#4

I'm reopening the question

Revision history for this message
Greg (gregfr) said :
#5

Sorry I had a typo, you should write:

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

(notice the last 2 characters).

It's in fact a javascript error that your browser you have displayed. When browser do you work with?

Revision history for this message
joha (johagood) said :
#6

Dear Greg,

I'm really sorry because i have change to another framework called yii. The reason is I need something to complete within very short time and i'm not able to waiting for your answer. I have done the same thing in Yii framework with less hassle. Anyway thank you for your framework cause i'm able to understand MVC in very short time.

Thank you

Can you help with this problem?

Provide an answer of your own, or ask joha for more information if necessary.

To post a message you must log in.