2016-03-07 57 views
0

我想创建一个基本的网页使用谷歌地图的地理位置。我嵌入地图很容易,但无法使“查找我按钮”正常工作。我做错了什么?试图创建一个基本的谷歌地图与一个按钮,可以找到我的当前位置

<!DOCTYPE html> 
<html lang=""> 
<head> 
<title></title> 
</head> 

<body> 

<a href="#" id="get_location">Find Me</a> 
<div id="map"> 
    <iframe id="google_map" width="425" height ="350" frameborder="0" scrolling="no" marginheight="0" marginwidth = "0" src="https://maps.google.co.uk?output=embed"></iframe> 
</div> 

<script> 
    var c =function (pos) { 
     var lat = pos.coords.latitude, 
       long = pos.coords.longitude, 
      coords = lat + ', ' + long; 

     document.getElementById('google_map').setAttribute('src',  'https://maps.google.co.uk/?q=' + coords + '&z=60&output=embed'); 

    document.getElementById('get_location').onclick = function() { 
     navigator.geolocation.getCurrentPosition(c); 
     return false; 
    } 

</script> 



</body> 
</html> 

查找我按钮不起作用。有任何想法吗?

回答

0

您缺少c()函数的右大括号。

var c = function(pos) { 
    var lat = pos.coords.latitude, 
     long = pos.coords.longitude, 
     coords = lat + ', ' + long; 

    document.getElementById('google_map').setAttribute('src', 'https://maps.google.co.uk/?q=' + coords + '&z=60&output=embed'); 
} // <-- HERE 

document.getElementById('get_location').onclick = function() { 
    navigator.geolocation.getCurrentPosition(c); 
    return false; 
} 

小提琴:https://jsfiddle.net/xot1fhsd/

相关问题