Google Maps API地圖應(yīng)用示例分享
效果(新版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;
// 設(shè)定地圖參數(shù),將當前位置的經(jīng)緯度設(shè)置為中心點
var latlng = new google.maps.LatLng(coords.latitude,coords.longitude);
var myOptions =
{
// 放大倍數(shù)
zoom:14,
// 標注坐標
center:latlng,
// 地圖類型
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map1;
// 顯示地圖
map1 = new google.maps.Map(document.getElementById('map'),myOptions);
// 創(chuàng)建標記
var marker = new google.maps.Marker(
{
position:latlng,
map:map1
});
// 設(shè)定標注窗口,附上注釋文字
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
相關(guān)文章
ionic js 復(fù)選框 與普通的 HTML 復(fù)選框到底有沒區(qū)別
本文通過實例給大家演示ionic js 復(fù)選框 與普通的 HTML 復(fù)選框到底有沒區(qū)別的相關(guān)知識,非常不錯具有參考借鑒價值,感興趣的朋友一起學習吧2016-06-06JS中實現(xiàn)replaceAll的方法(實例代碼)
本文是對JS中實現(xiàn)replaceAll的方法進行了詳細的總結(jié)介紹,需要的朋友可以過來參考下,希望對大家有所幫助2013-11-11svg插入foreignObject無法響應(yīng)事件解決
這篇文章主要為大家介紹了svg插入foreignObject無法響應(yīng)事件解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-10-10javascript制作的網(wǎng)頁側(cè)邊彈出框思路及實現(xiàn)代碼
這篇文章主要介紹了javascript制作的網(wǎng)頁側(cè)邊彈出框思路及實現(xiàn)代碼,需要的朋友可以參考下2014-05-05