Webmastersite.net
Register Log In

Google Maps Integration
show a map location for an item

Comments on Google Maps Integration

Paul
developer

Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California

Total Topics: 61
Total Comments: 7868
Paul
Posted Mar 08, 2007 - 10:54 PM:

1) Get your google maps API key at http://www.google.com/apis/maps/signup.html
2) At Admin -> Customizations -> Add Fields, add this setting field: googlemapskey
3) At Admin -> Customizations -> Add Fields, add these link fields (as text): lat, long
4) Copy your key into the admin panel where the googlemapskey field has been added (should be at the bottom of Admin -> Settings -> General if I recall).
5) In your wrapper template, change your <body> tag to this:
<body onload="load()" onunload="GUnload()">
6) Place this where you want to show the map (presumably your 'link details' template):

<IF {LINKLAT} and {LINKLONG}>
<script src="http://maps.google.com/maps?file=api&v=2&key={GOOGLEMAPSKEY}"
type="text/javascript"></script>
<script type="text/javascript">

//<![CDATA[

function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng({LINKLAT}, {LINKLONG}), 13);
}
}

//]]>
</script>

<div id="map" style="width: 500px; height: 300px"></div>
</IF>

7) Type in lattitude and longitude values for the desired links. Example lat and long: 37.4419, -122.1419
Paul
developer

Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California

Total Topics: 61
Total Comments: 7868
Paul
Posted Mar 10, 2007 - 12:38 AM:

Suppose you have fields requesting an address for each link, and want to automatically map the address without needing to manually determine the latitude/longitude. This becomes problematic. Here's an option though with these disclaimers:
- I gather it may not work for non-American addresses
- It requires purchase for commercial use
- It slows down page loads (though a more complex hack could fix that)

8) Create an account with http://geocoder.us

9) If you don't already have address fields, create link fields address1, city, state, zip.

10) Fill in your geocoder username and password at the top of this code, and also set the address according to the fields you have (if different). Finally replace the code from step 6 of post 1 with this:
<IF {LINKADDRESS1}> 
<?php
$geouser = 'yourgeocoderusername';
$geopass = 'yourgeocoderpassword';
$q = "{LINKADDRESS1}, {LINKCITY}, {LINKSTATE} {LINKZIP}"; // presumes you have fields address1, city, state, zip
$base = $_SERVER['PHP_SELF'] . "?address=" . $q ;
$filler = "http://". $geouser .":". $geopass ."@geocoder.us/member/service/csv?address=" . (urlencode($q));
$gm = fopen($filler,"r");
$tmp = fgetcsv($gm,8000);
fclose($gm);
$la = $tmp["0"];
$lo = $tmp["1"];
?>
<script src="http://maps.google.com/maps?file=api&v=2&key={GOOGLEMAPSKEY}"
type="text/javascript"></script>
<script type="text/javascript">

//<![CDATA[

function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(<?php echo $la; ?>, <?php echo $lo; ?>), 13);
}
}

//]]>
</script>

<div id="map" style="width: 500px; height: 300px"></div>
</IF>
Search thread for
Download thread as
  • 0/5
  • 1
  • 2
  • 3
  • 4
  • 5



This thread is closed, so you cannot post a reply.