Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: API javascript

  1. #1
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    API javascript

    Code:
    <!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&amp;v=2.x&amp;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 echo "$map_address"; ?>')">
     
     
     <div id="map_canvas" style="width: 250px; height: 200px"></div>
     
    </body>
    </html>
    I need to get it load australia map automatically. Can anyone help pls. About code is not working

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    I tried this and it worked for me in firefox

    I took a guess moved the map to my city.

    then in the address bar I wrote

    javascript:map.getCenter()

    hit enter and bingo!!!
    Last edited by TinyScript; 05-07-2009 at 09:34 AM.

  • #3
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts


    the location returned in this image is actually from down under. I didn't save the right map image
    Last edited by TinyScript; 05-07-2009 at 09:39 AM.

  • #4
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it doesn't work for me in internet. http://www.sgfairdeal.com/tes1.php I want it to show australia map instead of default singapore pls help amend the coding above

  • #5
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    move the map to the place you want it to open up at.
    put the
    javascript:map.getCenter()
    in the address bar and hit click
    copy and paste the output in place of the current start location


    this is the map location of the image you see above
    map.setCenter(new GLatLng(-34.894942447397305, 138.592529296875), 13);

  • #6
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts

    Code:
    <!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&amp;v=2.x&amp;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(-26.273714024406416, 134.6484375), 3);
    		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 echo "$map_address"; ?>')">
     
     
     <div id="map_canvas" style="width: 250px; height: 200px"></div>
     
    </body>
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •