Reply to Google Map function

Your name:

Reply:


Posted by windandwaves on 02/15/06 13:28

Hi Folk

Some of you may find this function useful. It makes it easier to create
maps using Google Maps. I link it to a database of points. The main use of
the function is that it creates all the javascript needed for Google maps to
work.

Any questions or comments? Please ask.

Nicolaas

<?php
/*
CSS
div#map =
ul#Gmapmain = main options for the html list
ul#Gmapgoto = list of actual points on the map
div#map = the actual map, must provide width and height
div.marker = "info window"

VARIABLES
$start_lon = longitude to start wtih
$start_lat = latitude to start with,
$start_zoo = start zoom level,
$Gkey = your Google Key (you need to get this from Google),
$alsoload = other javascripts that should load,
$data: DATA SHOULD CONTAINS:
NAM = name of the point (e.g. NY)
LON = longitude,
LAT = latitude,
HTM = html for the info box,
STA = number of the group the point belongs to,
STA = 0 is show on open
STA = 9 ~ all groups
GRN = name of the gorup the point belongs to,
ZOO = the default zoom level for the point
$htmllist = show the list of points in an html-formatted list (0 = no, 1 =
yes)
*/
//variables
function Gmapper($start_lon, $start_lat, $start_zoo, $Gkey, $alsoload,
$data, $htmllist = 0 ) {
$imgfolderjs = str_replace("/", "\/", "i/Ms/");
$var = 'var map;
var baseIcon = new GIcon();
baseIcon.shadow = "";
baseIcon.iconSize = new GSize(15, 26);
baseIcon.shadowSize = new GSize(1, 1);
baseIcon.iconAnchor = new GPoint(7, 26);
baseIcon.infoWindowAnchor = new GPoint(7, 10);
baseIcon.infoShadowAnchor = new GPoint(12, 20);
var iml = new Array();
var h = new Array();
var a = new Array();
var o = new Array();
var s = new Array();
var iml = new Array();
var httx = "'.$local_http.'";';
$js = '
function addPoI(status, z) {
map.centerAndZoom(new GPoint('.$start_lon.', '.$start_lat.'), z);';
$j = 0;
$i = 0;
$staex = 0;
$list = '<ul id="Gmapgoto">';
foreach($data as $ds) {
$gpclass = 'gp'.$ds["STA"];
if($ds["STA"] != $staex && $i > 0) {
$list .= '
</ul></li>';
$js .= '
}';
}
if($i == 0 || $ds["STA"] != $staex) {
$list .= '
<li id="'.$gpclass.'"><a href="#" onclick="return !addPoI('.$ds["STA"].',
'.$ds["ZOO"].'); ">'.$ds["GRN"].'</a><ul>';
$js .= '
if(status == '.$ds["STA"].' || status == 9) {';
}
$staex = $ds["STA"];
$var .= '
h['.$i.'] = \''.$ds["HTM"].'\'; a['.$i.'] = \''.$ds["LAT"].'\'; o['.$i.'] =
\''.$ds["LON"].'\'; s['.$i.'] = \''.$ds["STA"].'\';
';
$js .= '
markme('.$i.'); ';
$list .= '
<li><a href="#" onclick="return
!zoomer('.$i.');">'.$ds["NAM"].'</a></li>';
$i++;
}
$list .= '</ul></li></ul>';
$js .= '
}
return true;
}
function zoomer(i) {
map.recenterOrPanToLatLng(new GPoint(o[i], a[i]));
markme (i, 1);
return true;
}
function markme (i, show) {
var icon = new GIcon(baseIcon);
icon.image = "'.$imgfolderjs.'marker" + s[i] + ".gif";
var point = new GPoint(o[i],a[i]);
var marker = new GMarker(point, icon);
map.addOverlay(marker);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(\'<div class="marker">\' + h[i] + \'</div>\'); });
if(show == 1) {
marker.openInfoWindowHtml(\'<div class="marker">\' + h[i] + \'</div>\');
}
return marker;
}
function loadims (imgx, i) {
if( window.Image ) {
iml[i] = new Image();
iml[i].src = imgx;
}
}
function starter(o, a, z) {
if(!GBrowserIsCompatible()) {
alert("Your browsers does not support this map. Please Get Firefox
(www.getfirefox.com).");
}
else {
map.clearOverlays();
map.centerAndZoom(new GPoint(o, a), z);
return true;
}
}
function go () {
'.$alsoload.'
map = new GMap(document.getElementById("map"),[G_SATELLITE_TYPE]);
map.addControl(new GSmallMapControl());
starter('.$start_lon.', '.$start_lat.', '.$start_zoo.');
addPoI(0, '.$start_zoo.');
return true;
}
window.onload = go;';
$v[0] = '
<div id="map"></div>
<script
src="http://maps.google.com/maps?file=api&amp;v=1&amp;key='.$Gkey.'"
type="text/javascript"></script>
<script type="text/javascript">
'.$var.'
'.$js.'
</script>';
if($htmllist) {
$v[1] .= '
<h2>Main options: </h2>
<ul id="Gmapmain">
<li><a href="#" onclick="return !go(\''.$start_lon.'\',\''.$start_lat.'\',
\''.$start_zoo.'\'); ">start over</a></li>
<li><a href="#" onclick="return !addPoI(9, '.$start_zoo.'); ">show all</a>
</ul>
<h2>go to...</h2>
'.$list;
}
return $v;
}


?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация