欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
您可以使用地理位置数据来做非常有趣的事情,例如在Google地图上显示用户位置。以下示例将根据通过HTML5地理位置功能检索的纬度和经度数据显示您在Google地图上的当前位置。
 
例试试这个代码»
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Using the Google Maps</title>
<script>
    function showPosition() {
        navigator.geolocation.getCurrentPosition(showMap);
    }
    
    function showMap(position) {
        // Get location data
        var latlong = position.coords.latitude + "," + position.coords.longitude;
        
        // Set Google map source url
        var mapLink = "https://maps.googleapis.com/maps/api/staticmap?center="+latlong+"&zoom=16&size=400x300&output=embed";
        
        // Create and insert Google map
        document.getElementById("embedMap").innerHTML = "<img alt='Map Holder' src='"+ mapLink +"'>";
    }
</script>
</head>
<body>
    <button type="button" onclick="showPosition();">Show My Position on Google Map</button>
    <div id="embedMap">
        <!--Google map will be embedded here-->
    </div>
</body>
</html>

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h61002.shtml