Tags:
google-maps
hej alle.
Har sådan en google map kørene på en webside og har sådan 2 filer der er lavet til v2 api hvor den sætter en start adresse selv og man så skriver slut adresse og det så bliver vist som rute.
men kunne godt tænke mig og få den til og virke i v3 af google map. men ved ikke rigtig hvor meget kode der skal skrives om håber der en der kan hjælpe herinde.
smider lige de to filer op
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Find vej til din varer</title>
<script src="http://maps.google.com/maps?file=api&v=2&sensor=true&key=min key" type="text/javascript"></script>
<style type="text/css">
body {
font-family: Verdana, Arial, sans serif;
font-size: 11px;
margin: 2px;
}
table.directions th {
background-color:#EEEEEE;
}
img {
color: #000000;
}
</style>
<script type="text/javascript">
var map;
var gdir;
var geocoder = null;
var addressMarker;
var fulladdress = unescape(location.search.substring(1,location.search.length)) ;
var toend = fulladdress.indexOf('&') ;
var fromAddress = fulladdress.substring(5,toend) ;
fromAddress = fromAddress.replace(/\+/g, ' ') ;
var fromend = fulladdress.indexOf('&', toend+1) ;
var toAddress = fulladdress.substring(toend+4,fromend) ;
toAddress = toAddress.replace(/\+/g, ' ');
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl()) ;
//map.addControl(new GOverviewMapControl()) ;
gdir = new GDirections(map, document.getElementById("directions"));
GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);
setDirections(fromAddress, toAddress , "da_DA");
}
}
function setDirections(fromAddress, toAddress, locale) {
gdir.load("from: " + fromAddress + " to: " + toAddress,
{ "locale": locale });
}
function handleErrors(){
if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
// else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS) <--- Doc bug... this is either not defined, or Doc is wrong
// alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_KEY)
alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
else alert("An unknown error occurred.");
}
function onGDirectionsLoad(){
// Use this function to access information about the latest load()
// results.
// e.g.
// document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
// and yada yada yada...
}
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
<form action="#" onsubmit="setDirections(this.from.value, this.to.value, this.locale.value); return false">
<table>
<tr><th align="right">Fra: </th>
<td>
<script language="javascript">
toAddress = toAddress.replace(/\+/g, ' ') ;
document.write('<input type="text" size="25" id="fromAddress" name="from" value="' + fromAddress + '" />') ;
</script>
</td>
<th align="right"> Til: </th>
<td align="right">
<script language="javascript">
toAddress = toAddress.replace(/\+/g, ' ') ;
document.write('<input type="text" size="25" id="toAddress" name="to" value="' + toAddress + '" />') ;
</script>
</td></tr>
<tr>
<td colspan="3">
</select>
<input name="submit" type="submit" value="Klik her for og lave rute" />
</td></tr>
</table>
</form>
<br/>
<table class="directions">
<tr><th>Ruten</th><th>Kort</th></tr>
<tr>
<td valign="top"><div id="directions" style="width: 200px"></div></td>
<td valign="top"><div id="map_canvas" style="width: 385px; height: 400px"></div></td>
</tr>
</table>
</body>
</html>
----------------------------------------------------------------------------
og her er den der åbner kort
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>find på kort</title>
<link href="/standard.css" media="screen" rel="Stylesheet" type="text/css">
<script src="http://maps.google.com/maps?file=api&v=2&sensor=true&key=min key" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var geocoder ;
var icon ;
var gicon ;
var map ;
function load()
{
map = new GMap2(document.getElementById("map"));
var start = new GLatLng(54.7736870057,11.8679974179);
map.setCenter(start, 3);
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl()) ;
map.addControl(new GOverviewMapControl()) ;
geocoder = new GClientGeocoder() ;
var address = unescape(location.search.substring(1,location.search.length)) ;
address = address.replace(/\+/g, ' ') ;
showAddress(address) ;
}
function showAddress(address)
{
document.title = address ;
geocoder.getLatLng( address, function(point)
{
if (!point)
{
alert(address + " not found")
} else
{
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml('<br> find vej til:<br><span style="color: #2A1FAA; font-weight: bold;" >' + address + '</span> <br>fra:<form action="dir_map.htm" onsubmit="post"><input type="text" size="25" id="fromAddress" name="from" value=""/><input type="hidden" size="25" id="toAddress" name="to" value="' + address + '" /><br><input name="submit" type="submit" value="Lav rute!" /></form>');
}
}) ;
}
//]]>
</script>
</style>
</head>
<body bgcolor="#ffffff" text="black" link="#444444" alink="gray" vlink="#111111" onload="load();" onunload="GUnload()">
<div align="center" valign="center" >
<table width="100%" height="100%" border=0 valign="center" align="center" cellPadding=2 cellSpacing=2>
<tr width="100%">
<script language="javascript">
<!--
if( window.innerHeight )
{
var width = 500 ;
var height = 500 ;
} else
{
var width = 500 ;
var height = 500 ;
}
document.write('<td valign=center align=center width=' + width + '><div valign="center" align="center" id="map" style="width: ' + width + 'px; height:' + height + 'px; border: thin solid black;"></div>') ;
// -->
</script>
</td>
</tr>
</table>
</div>
</body>
</html>
3 svar postet i denne tråd vises herunder
1 indlæg har modtaget i alt 1 karma
1
kan du ikke lige smide det i [ code ] klammer?
i en hvad for noget.
det er ikon nr 5 over den tekstboks du skriver dit indlæg i..
screenshot:
http://kenneth.wi.ots.dk/udvikleren/udv_kode_box.png
jeg er en kodebox :)
Indlæg senest redigeret d. 05.05.2012 14:34 af Bruger #3427
0
kan du ikke lige smide det i [code] klammer?
0