Google Maps Snippet

Published: 2009-11-07

Absolute bare basics when it comes the Google Map api but a snippet of code that I tend to use as the basis for a lot of scripts using a postcode search and map plotting...

<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=KEY'
type='text/javascript'></script>  
<script src='http://www.google.com/uds/api?file=uds.js&amp;v=1.0&amp;key=KEY'
type='text/javascript'></script>  
<script type="text/javascript">
    var localSearch = new GlocalSearch();  
     localSearch.setSearchCompleteCallback(null, function(){  
        if(localSearch.results[0]){  
            var mag = 16;
            var map = new GMap2(document.getElementById("map"));
            map.addControl(new GSmallMapControl());
            pos = new GLatLng(localSearch.results[0].lat,
localSearch.results[0].lng);
            marker = new GMarker(pos);
            map.addOverlay(marker);
            map.setCenter(pos, mag);
            return true;  
        }
        else return false; 
    });  
    localSearch.execute("HG1 1HL, UK");
</script>
<div id="map" style="width:400px; height:400px;"></div>

More from this section

RECENT ARTICLES

Lightweight blog created on Ruby/GAA/Datastore stack

Put this together a month or two back but never got around to replaci... read more

Using Node JS and Couch DB Stack for Web Dev

With the recent hype surrounding Node.js I thought I'd better get my ... read more

Campaign Monitor API Using PHP and SOAP

Campaign Monitor has a fairly comprehensive API and support docs.&nbs... read more

Google Maps Snippet

Absolute bare basics when it comes the Google Map api but a snippet o... read more

CREDITS

powered by php-wax the php framework