Jump to content

[SOLVED] php and javascipt API


sungpeng

Recommended Posts

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>sgfairdeal</title>
    <script src="http://maps.google.com/maps?file=api&v=2.x&key=your key" type="text/javascript"></script>
    <script type="text/javascript">

    var map = null;
    var geocoder = null;
    var map = null;
    var geocoder = null;
    
    function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(1.3714, 103.8861), 13);
	map.addControl(new GSmallMapControl());
        geocoder = new GClientGeocoder();
      }
    }
    
    function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
            }
          }
        );
      }
    }

</script>

</head>
<?php $map_address="australia"; ?>
<body onload="initialize()" onunload="GUnload()" onload="showAddress('<?php$map_address?>')">


<div id="map_canvas" style="width: 250px; height: 200px"></div>

</body>
</html>

Part of it is php. I need it to show the australia map straight away. Can anyone help pls?

Link to comment
https://forums.phpfreaks.com/topic/157190-solved-php-and-javascipt-api/
Share on other sites

This code looks like it is setting co-ordinates:

 

map.setCenter(new GLatLng(1.3714, 103.8861), 13);

 

Are they the latitude and longitude co-ordinates of Singapore? If so, try changing them to whatever the lat and long co-ordinates of Australia are. Although born and bred in Australia, I have no idea where I am on the globe in lat/long co-ordinates. :)

If this is supposed to display Australia on the map, then it's not working as you can only have 1 onload call...

 

onload="showAddress('<?php echo $map_address; ?>')"

 

Use instead:

 

<body onload="initialize(); showAddress('<?php echo $map_address; ?>');" onunload="GUnload();">

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.