作为一名相对较新的网络开发和javascript / html的CS学生,我一直在弄清楚如何使用Google Maps Javascript API的基础知识。
我的最终目标是能够输入两个地址并计算它们之间的距离,我找到了一些使用google maps API执行此操作的示例。但是,我在确定如何实际下载/安装/包含API代码时遇到了困难。
我找到了一些链接给出了这样的例子:
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
另一个链接提到需要谷歌开发者控制台的密钥(我有)。
那么我究竟如何包含API代码以便我可以开始使用它并开始使用以下示例?
由于
答案 0 :(得分:1)
根据W3Schools,您需要包含<script src="http://maps.googleapis.com/maps/api/js"></script>
才能包含API脚本。
他们举例说明如何在网站上使用。以下是您可以做的事情的示例:
<!DOCTYPE html>
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script>
function initialize() {
var mapProp = {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="googleMap" style="width:500px;height:380px;"></div>
</body>
</html>
更多信息和入门指南:http://www.w3schools.com/googleapi/google_maps_basic.asp