Google Maps API地图应用示例分享

2019-12-21,,,

效果(新版Firefox中测试):

代码:

<!DOCTYPE>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Google Map</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function init()
{
// 获取当前位置
navigator.geolocation.getCurrentPosition(function(position)
{
var coords = position.coords;
// 设定地图参数,将当前位置的经纬度设置为中心点
var latlng = new google.maps.LatLng(coords.latitude,coords.longitude);
var myOptions =
{
// 放大倍数
zoom:14,
// 标注坐标
center:latlng,
// 地图类型
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map1;
// 显示地图
map1 = new google.maps.Map(document.getElementById('map'),myOptions);
// 创建标记
var marker = new google.maps.Marker(
{
position:latlng,
map:map1
});
// 设定标注窗口,附上注释文字
var infowindow = new google.maps.InfoWindow(
{
content:"当前位置"
});
// 打开标注窗口
infowindow.open(map1,marker);
});
}
</script>
</head>
<body onload="init()">
<div id="map"></div>
</body>
</html>

Google Maps JavaScript API v3(参考文档):https://developers.google.com/maps/documentation/javascript/basics

百度地图API的参考文档:http://developer.baidu.com/map/jsmobile.htm

您可能感兴趣的文章:

  • Google 地图API资料整理及详细介绍
  • Google 地图类型详解及示例代码
  • Google 地图控件集详解及实例代码
  • Google 地图事件实例讲解
  • Google 地图叠加层实例讲解
  • Google 地图获取API Key详细教程
  • 百度地图经纬度转换到腾讯地图/Google 对应的经纬度
  • js+html5获取用户地理位置信息并在Google地图上显示的方法
  • 在Google 地图上实现做的标记相连接
  • Google 地图API Map()构造器详解

《Google Maps API地图应用示例分享.doc》

下载本文的Word格式文档,以方便收藏与打印。