html5指南-7.geolocation結(jié)合google maps開發(fā)一個(gè)小的應(yīng)用_HTML5教程
推薦:使用html5+css3來實(shí)現(xiàn)slider切換效果告別javascript+css提到slider,過去一直都是用css+js來配合實(shí)現(xiàn)相關(guān)的切換效果。聽過大家一直討論使用html5+css3的實(shí)現(xiàn)方式,自己卻一直沒有動(dòng)手實(shí)現(xiàn)過。好吧,這次我有時(shí)間來玩下css3了,感興趣的朋友可以了解下哦
今天我們將把HTML5/">html5的geolocation結(jié)合google maps開發(fā)一個(gè)小的應(yīng)用。google maps的api地址:https://developers.google.com/maps/documentation/javascript/?hl=zh-CN。調(diào)用google maps,實(shí)現(xiàn)需要添加js引用<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>,其中sensor參數(shù)的具體含義:
要使用 Google Maps API,您需要指明自己的應(yīng)用程序在任何 Maps API 庫(kù)或服務(wù)請(qǐng)求中是否是使用傳感器(如 GPS 定位器)來確定用戶所處位置的。這對(duì)移動(dòng)設(shè)備尤為重要。如果您的 Google Maps API 應(yīng)用程序使用任何形式的傳感器確定訪問您的應(yīng)用程序的設(shè)備的位置,那么您必須通過將 sensor 參數(shù)值設(shè)置為 true 以聲明這一點(diǎn)。
html部分比較簡(jiǎn)單,只需要準(zhǔn)備一個(gè)div就可:
復(fù)制代碼 代碼如下:m.dounai2.com
<body>
<div id="map">
</div>
</body>
js代碼的框架如下:
復(fù)制代碼 代碼如下:m.dounai2.com
<script type="text/javascript">
var map;
var browserSupport = false;
var attempts = 0;
$(document).ready(function () {
//初始化地圖
InitMap();
//定位
getLocation();
//定位跟蹤
watchLocation();
});
function InitMap() {
/* Set all of the options for the map */
var options = {
};
/* Create a new Map for the application */
map = new google.maps.Map($('#map')[0], options);
}
/*
* If the W3C Geolocation object is available then get the current
* location, otherwise report the problem
*/
function getLocation() {
}
function watchLocation() {
}
/* Plot the location on the map and zoom to it */
function plotLocation(position) {
}
/* Report any errors using this function */
function reportProblem(e) {
}
</script>
InitMap方法就是調(diào)用google maps api初始化地圖,他需要設(shè)置options對(duì)象,在調(diào)用地圖初始化的時(shí)候使用。
復(fù)制代碼 代碼如下:m.dounai2.com
function InitMap() {
/* Set all of the options for the map */
var options = {
zoom: 4,
center: new google.maps.LatLng(38.6201, -90.2003),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR,
position: google.maps.ControlPosition.BOTTOM_CENTER
},
panControl: true,
panControlOptions: {
position: google.maps.ControlPosition.TOP_RIGHT
},
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.LARGE,
position: google.maps.ControlPosition.LEFT_CENTER
},
scaleControl: true,
scaleControlOptions: {
position: google.maps.ControlPosition.BOTTOM_LEFT
},
streetViewControl: true,
streetViewControlOptions: {
position: google.maps.ControlPosition.LEFT_TOP
}
};
/* Create a new Map for the application */
map = new google.maps.Map($('#map')[0], options);
}
getLocation和watchLocation方法獲取定位信息。
復(fù)制代碼 代碼如下:m.dounai2.com
function getLocation() {
/* Check if the browser supports the W3C Geolocation API */
if (navigator.geolocation) {
browserSupport = true;
navigator.geolocation.getCurrentPosition(plotLocation, reportProblem, { timeout: 45000 });
} else {
reportProblem();
}
}
function watchLocation() {
/* Check if the browser supports the W3C Geolocation API */
if (navigator.geolocation) {
browserSupport = true;
navigator.geolocation.watchPosition(plotLocation, reportProblem, { timeout: 45000 });
} else {
reportProblem();
}
}
成功獲取位置信息后,調(diào)用plotLocation方法把位置顯示在google maps上。
復(fù)制代碼 代碼如下:m.dounai2.com
function plotLocation(position) {
attempts = 0;
var point = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var marker = new google.maps.Marker({
position: point
});
marker.setMap(map);
map.setCenter(point);
map.setZoom(15);
}
demo下載地址:googleMapGeolocation.rar
分享:css3 transform 3d 使用css3創(chuàng)建動(dòng)態(tài)3d立方體(html5實(shí)踐)在今天的課程中,我將向大家介紹如何使用css3創(chuàng)建3d的立方體,操作方法為:上下左右鍵,實(shí)現(xiàn)立方體的翻轉(zhuǎn)旋轉(zhuǎn)效果,特酷,本人看后,目瞪口呆,值得收藏于參考
相關(guān)HTML5教程:
- 只要五步 就可以用HTML5/CSS3快速制作便簽貼特效(圖)
- 網(wǎng)易微博Web App用HTML5開發(fā)的過程介紹
- HTML5 對(duì)各個(gè)標(biāo)簽的定義與規(guī)定:body的介紹
- 關(guān)于HTML5的安全問題開發(fā)人員需要牢記的
- 關(guān)于HTML5的22個(gè)初級(jí)技巧(圖文教程)
- 開發(fā)人員所需要知道的HTML5性能分析面面觀
- HTML5 Web Database 數(shù)據(jù)庫(kù)的SQL語(yǔ)句的使用方法
- HTML5實(shí)踐-圖片設(shè)置成灰度圖
- HTML5安全介紹之內(nèi)容安全策略(CSP)簡(jiǎn)介
- HTML5 Web存儲(chǔ)方式的localStorage和sessionStorage進(jìn)行數(shù)據(jù)本地存儲(chǔ)案例應(yīng)用
- Bootstrap 學(xué)習(xí)分享
- input元素的url類型和email類型簡(jiǎn)介
HTML5教程Rss訂閱Div+Css教程搜索
HTML5教程推薦
- html5 canvas 畫圖教程案例分析
- html5的新增的標(biāo)簽和廢除的標(biāo)簽簡(jiǎn)要概述
- html5 Canvas畫圖教程(7)—canvas里畫曲線之quadraticCurveTo方法
- HTML5中Canvas與SVG的畫圖原理比較
- html5 Canvas畫圖教程(11)—使用lineTo/arc/bezierCurveTo畫橢圓形
- HTML5離線緩存在tomcat下部署可實(shí)現(xiàn)圖片flash等離線瀏覽
- 檢測(cè)瀏覽器是否支持html5視頻的代碼
- HTML5引入的新數(shù)組TypedArray介紹
- 突襲HTML5之Javascript API擴(kuò)展1—Web Worker異步執(zhí)行及相關(guān)概述
- HTML5之SVG 2D入門12—SVG DOM及DOM操作介紹
- 相關(guān)鏈接:
復(fù)制本頁(yè)鏈接| 搜索html5指南-7.geolocation結(jié)合google maps開發(fā)一個(gè)小的應(yīng)用
- 教程說明:
HTML5教程-html5指南-7.geolocation結(jié)合google maps開發(fā)一個(gè)小的應(yīng)用。