Okay kunne se der var lidt små fejl i koden jeg gav dig tidliger.
et her skulle meget gerne virker.
whatever.php
- <html>
- <head></head>
- <body onload="initialize('Vesterbrogade 3, 1630 københavn');">
- <div id="map_canvas" style="width:450px; height:450px"></div>
- <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
- <script type="text/javascript" src="google_maps.js"></script>
- </body>
- </html>
google_maps.js
- function initialize(location) {
- var api_key = "------ HUSK API KEY HER ------";
-
- location = location.replace(" ", "+");
- var s = document.createElement('script');
- s.src = "http://maps.google.com/maps/geo?output=json&oe=utf-8&q="+location+"&key="+api_key+"&mapclient=jsapi&hl=en&callback=loadmap";
- s.type = 'text/javascript';
- document.getElementsByTagName('head')[0].appendChild(s);
- }
-
- function loadmap(result){
- if(result.Status.code != 200){
- alert("fejl!");
- return false;
- }
-
- var lat = result.Placemark[0].Point.coordinates[1];
- var lng = result.Placemark[0].Point.coordinates[0];
-
- //koordinater til map
- var centerMapLat = lat; //55.403756;
- var centerMapLng = lng; //10.40237;
-
- //koordinater og indhold til marker
- var infoWindowText = "tekst/html <strong>her</strong>";
- var positionMarkerLat = lat; //55.403756;
- var positionMarkerLng = lng; //10.40237;
-
- var initialZoom = 14;
-
- var latlng = new google.maps.LatLng(centerMapLat,centerMapLng);
- var myOptions = {zoom: initialZoom, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP};
- var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
- var infowindow = new google.maps.InfoWindow({ content: infoWindowText });
- var myLatLng = new google.maps.LatLng(positionMarkerLat,positionMarkerLng);
- var marker = new google.maps.Marker({position: myLatLng, map: map, title:""});
- google.maps.event.addListener(marker, 'click', function() {
- infowindow.open(map,marker);
- });
- }
Indlæg senest redigeret d. 28.07.2011 22:11 af Bruger #3427