2012-05-25 23 views
1

嗨,我是工作在此基礎上例如http://econym.org.uk/gmap/example_categories.htm在地圖上,並試圖地理位置增加,但每一次我嘗試添加了地理位置它打破了代碼的其餘部分的代碼的時間,所以我希望有人可以點我在正確的方向上如何得到它的工作添加地理定位到現有的谷歌地圖

我是新來的谷歌地圖和地理位置

我很抱歉,如果這個問題是被要求之前,我剛好可以」找不到答案,我需要

這是我使用我的index.html

頁面的代碼
<!DOCTYPE html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>Untitled Document</title> 

<link href="test.css" rel="stylesheet" type="text/css" media="all"> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<script type="text/javascript" src="scripts/downloadxml.js"></script> 
<script type="text/javascript" src="scripts/map.js"></script> 
</head> 

<body onload="initialize()"> 
<div class="main-container"> 
<img class="logo" src="images/testlogo.png" width="1000" height="150"> 
<div class="overall"> 

<div class="sidebar1"> 
<p>Home</p> 
<p>About Us</p> 
<p>Contact Us</p> 
<p>My Portfolio</p> 
<p>Links</p> 
</div> 

<div class="sidebar2"> 

<p>Hi My name is Robert Baron Austin and I'm the designer of this website and other sites like Spinfish.co.uk which was my first ever website that I handcoded by myself by using Dreamweaver, Photoshop and Illustrator.</p> 

</div> 

<div class="content1"> 

<p>Hi My name is Robert Baron Austin and I'm the designer of this website and other sites like Spinfish.co.uk bacwhich was my first ever website that I handcoded by myself by using Dreamweaver, Photoshop and Illustrator.</p> 

</div> 

<div class="content2"> 

<p>Hi My name is Robert Baron Austin and I'm the designer of this website and other sites like Spinfish.co.uk which was my first ever website that I handcoded by myself by using Dreamweaver, Photoshop and Illustrator.</p> 

</div> 

<div class="content3"> 

<p>Hi My name is Robert Baron Austin and I'm the designer of this website and other sites like Spinfish.co.uk which was my first ever website that I handcoded by myself by using Dreamweaver, Photoshop and Illustrator.</p> 

</div> 

<div class="content4"> 

<p class="images1"><img class="otherpics" src="../f5770309.jpg" width="150" height="150"></p> 
<p>Hi My name is Robert Baron Austin and I'm the designer of this website and other sites like Spinfish.co.uk which was my first ever website that I handcoded by myself by using Dreamweaver, Photoshop and Illustrator.</p> 
</div> 

<div class="content5"> 

<p>Hi My name is Robert Baron Austin and I'm the designer of this website and other sites like Spinfish.co.uk which was my first ever website that I handcoded by myself by using Dreamweaver, Photoshop and Illustrator.</p> 

</div> 

<div class="content6"> 

<p><div id="map"></div> 

<form class="form" action="#"> 
    Theatres: <input type="checkbox" id="theatrebox" onclick="boxclick(this,'theatre')" /> &nbsp;&nbsp; 
    Golf Courses: <input type="checkbox" id="golfbox" onclick="boxclick(this,'golf')" /> &nbsp;&nbsp; 
    Test: <input type="checkbox" id="testbox" onclick="boxclick(this,'test')" /> &nbsp;&nbsp; 
    Tourist Information: <input type="checkbox" id="infobox" onclick="boxclick(this,'info')" /><br /> 
</form></p> 

<div id="side_bar"></div> 

</div> 



</div> 


<div class="footer">footer</div> 

</div></div></body> 
</html> 

,這是JavaScript

//<![CDATA[ 
    // this variable will collect the html which will eventually be placed in the side_bar 
    var side_bar_html = ""; 

    var gmarkers = []; 
    var gicons = []; 
    var map = null; 

var infowindow = new google.maps.InfoWindow(
{ 
    size: new google.maps.Size(150,50) 
    }); 


    var iconImage = new google.maps.MarkerImage('mapIcons/marker_red.png', 
    // This marker is 20 pixels wide by 34 pixels tall. 
    new google.maps.Size(20, 34), 
    // The origin for this image is 0,0. 
    new google.maps.Point(0,0), 
    // The anchor for this image is at 9,34. 
    new google.maps.Point(9, 34)); 
    var iconShadow = new google.maps.MarkerImage('http://www.google.com/mapfiles/shadow50.png', 
    // The shadow image is larger in the horizontal dimension 
    // while the position and offset are the same as for the main image. 
    new google.maps.Size(37, 34), 
    new google.maps.Point(0,0), 
    new google.maps.Point(9, 34)); 
    // Shapes define the clickable region of the icon. 
    // The type defines an HTML &lt;area&gt; element 'poly' which 
    // traces out a polygon as a series of X,Y points. The final 
    // coordinate closes the poly by connecting to the first 
    // coordinate. 
    var iconShape = { 
    coord: [9,0,6,1,4,2,2,4,0,8,0,12,1,14,2,16,5,19,7,23,8,26,9,30,9,34,11,34,11,30,12,26,13,24,14,21,16,18,18,16,20,12,20,8,18,4,16,2,15,1,13,0], 
    type: 'poly' 
    }; 

    //Custom marker function 
     function createMarker(point) { 

    //Create the markers 
     return new google.maps.Marker({ 
     position: point, 
     map: map, 
     draggable: false 

    }); 

} 

    // A function to create the marker and set up the event window 
    function createMarker(latlng,name,html,category) { 
    var contentString = html; 
    var marker = new google.maps.Marker({ 
    position: latlng, 
    icon: gicons[category], 
    shadow: iconShadow, 
    map: map, 
    title: name, 
    zIndex: Math.round(latlng.lat()*-100000)<<5 
    }); 
    // === Store the category and name info as a marker properties === 
    marker.mycategory = category;         
    marker.myname = name; 
    gmarkers.push(marker); 

    google.maps.event.addListener(marker, 'click', function() { 
    infowindow.setContent(contentString); 
    infowindow.open(map,marker); 
    }); 
} 

    // == shows all markers of a particular category, and ensures the checkbox is checked == 
    function show(category) { 
    for (var i=0; i<gmarkers.length; i++) { 
     if (gmarkers[i].mycategory == category) { 
     gmarkers[i].setVisible(true); 
     } 
    } 
    // == check the checkbox == 
    document.getElementById(category+"box").checked = true; 
    } 

    // == hides all markers of a particular category, and ensures the checkbox is cleared == 
    function hide(category) { 
    for (var i=0; i<gmarkers.length; i++) { 
     if (gmarkers[i].mycategory == category) { 
     gmarkers[i].setVisible(false); 
     } 
    } 
    // == clear the checkbox == 
    document.getElementById(category+"box").checked = false; 
    // == close the info window, in case its open on a marker that we just hid 
    infowindow.close(); 
    } 

    // == a checkbox has been clicked == 
    function boxclick(box,category) { 
    if (box.checked) { 
     show(category); 
    } else { 
     hide(category); 
    } 
    // == rebuild the side bar 
    makeSidebar(); 
    } 

    function myclick(i) { 
    google.maps.event.trigger(gmarkers[i],"click"); 
    } 


    // == rebuilds the sidebar to match the markers currently displayed == 
    function makeSidebar() { 
    var html = ""; 
    for (var i=0; i<gmarkers.length; i++) { 
     if (gmarkers[i].getVisible()) { 
     html += '<a href="javascript:myclick(' + i + ')">' + gmarkers[i].myname + '<\/a><br>'; 
     } 
    } 
    document.getElementById("side_bar").innerHTML = html; 
    } 

function initialize() { 
    var myOptions = { 
    zoom: 10, 
    center: new google.maps.LatLng(53.8363,-3.0377), 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
    } 
    map = new google.maps.Map(document.getElementById("map"), myOptions); 


    google.maps.event.addListener(map, 'click', function() { 
    infowindow.close(); 
    }); 



    // Read the data 
    downloadUrl("categories.xml", function(doc) { 
    var xml = xmlParse(doc); 
    var markers = xml.documentElement.getElementsByTagName("marker"); 

    for (var i = 0; i < markers.length; i++) { 
     // obtain the attribues of each marker 
     var lat = parseFloat(markers[i].getAttribute("lat")); 
     var lng = parseFloat(markers[i].getAttribute("lng")); 
     var point = new google.maps.LatLng(lat,lng); 
     var address = markers[i].getAttribute("address"); 
     var name = markers[i].getAttribute("name"); 
     var html = "<b>"+name+"<\/b><p>"+address; 
     var category = markers[i].getAttribute("category"); 
     // create the marker 
     var marker = createMarker(point,name,html,category); 
    } 

    // == show or hide the categories initially == 
    hide("theatre"); 
    hide("golf"); 
    hide("info"); 
    hide("test"); 
    // == create the initial sidebar == 
    makeSidebar(); 
    }); 
} 

// This Javascript is based on code provided by the 
// Community Church Javascript Team 
// http://www.bisphamchurch.org.uk/ 
// http://econym.org.uk/gmap/ 
// from the v2 tutorial page at: 
// http://econym.org.uk/gmap/example_categories.htm 
//]]> 
+0

你能多一點具體的你在做什麼試圖實現。 – barro32

+0

嗨感謝您的答覆,我想在地理位置我的版本上面鏈接的網站添加到地圖中,所以當用戶來到到我的網站,他們將與他們的位置呈現,然後可以從地點列表中選擇感興趣 –

回答

0

對你有包括谷歌地圖API時使用sensor=true開始

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script> 
+0

哦,好,謝謝巴里奧的,我要在正確的地方的編碼我認爲這是我的問題 –

+0

仍然有這個問題的一部分,我似乎無法得到它去 –