google maps not showing actual map and postcode

Posted by Andy on Stack Overflow See other posts from Stack Overflow or by Andy
Published on 2010-05-17T21:37:53Z Indexed on 2010/05/17 21:40 UTC
Read the original article Hit count: 309

Filed under:
|
|

Im trying to pass a dynamically generated postode to a page. But currently its not showing the map correctly. Any ideas?

Heres my head tag

<script src="http://www.google.com/jsapi?key=ABQIAAAANQzcZVPOkiHWMZO3zxREGRSlIja3KBL7jZ08tky_uJrV3vVYdxTCwTHJPA2Vn06DLdnCWvRW_w7VYQ" type="text/javascript"></script>
    <script language="Javascript" type="text/javascript">
    var localSearch;
var map;
var icon;
var addressMarkerOptions;
google.load("search", "1");
google.load("maps", "2");
google.setOnLoadCallback(initialize);

function initialize()
{
  localSearch = new GlocalSearch();
  icon = new GIcon(G_DEFAULT_ICON);
  addressMarkerOptions = { icon:icon , draggable: false};
  map = new GMap2(document.getElementById("map"));
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  plotAddress("OX4 1FJ");
}

/**
* This takes either a postcode or an address string
*
*/
function plotAddress(address)
{
  localSearch.setSearchCompleteCallback(null, 
    function() {

      if (localSearch.results[0])
      {     
        var resultLat = localSearch.results[0].lat;
        var resultLng = localSearch.results[0].lng;
        var point = new GLatLng(resultLat,resultLng);
        var marker = new GMarker(point, addressMarkerOptions);
        map.addOverlay(marker);
        map.setCenter(point, 5, G_NORMAL_MAP);
      }
      else
      {
        alert('address not found');
      }
    });

  localSearch.execute(address + ", UK");
}

    </script>

It slots into the code below:

<div id="map">Loading...</div>

© Stack Overflow or respective owner

Related posts about google-maps

Related posts about google