最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

在AngularJS中如何使用谷歌地圖把當前位置顯示出來

 更新時間:2016年01月25日 11:33:43   作者:Darren Ji  
這篇文章給的大家介紹在AngularJS中如何使用谷歌地圖把當前位置顯示出來,本文介紹的非常詳細,具有參考借鑒價值,對angularjs 谷歌地圖相關知識感興趣的朋友一起學習吧

--在html5中,為我們提供了navigator.geolocation.getCurrentPosition(f1, f2)函數(shù),f1是定位成功調(diào)用的函數(shù),f2是定位失敗調(diào)用的函數(shù),而且會把當前的地理位置信息作為實參傳遞給f1和f2函數(shù)。f1函數(shù)調(diào)用谷歌地圖的API即可。

如何展示呢?

--需要一個提示信息和展示地圖的一個區(qū)域。

頁面上,大致是這樣:

<map-geo-location height="400" width="600"></map-geo-location>
<script src="angular.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script src=="mapGeoLocation.js"></script>

Directive部分如下:

(function(){
var mapGeoLocation = ['$window', function($window){
var template = '<p><span id="status">正在查找地址...</span></p>' + '<br /><div id="map"></div>',
mapContainer = null,
status = null;
function link(scope, elem, attrs){
//以Angular的方式獲取Angular元素
status = angular.element(document.getElementById('status'));
mapContainer = angular.element(document.getElementById('map'));
mapContainer.attr('style', 'height:' + scope.height + 'px;width:' + scope.width + 'px');
$window.navigator.geolocation.getCurrentPosition(mapLocation, geoError);
}
//定位成功時調(diào)用
function mapLocation(pos){
status.html('found your location! Longitude: ' + pos.coords.longitude + ' Latitude: ' + pos.coords.latitude);
var latlng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
var optons = {
zoom:15,
center: latlng,
myTypeCOntrol: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(mapContainer[0], options);
var marker = new google.maps.Markser({
position: latlng,
map: map, 
title: "Your location"
});
}
//定位失敗時調(diào)用
function geoError(error){
status.html('failed lookup ' + error.message);
}
return {
restrict: 'EA', //默認
scope:{
height: '@',
width:'@'
},
link: link,
template: template
}
}];
angular.module('direcitveModule',[])
.direcitve('mapGeoLocation', mapGeoLocation);
}());

以上所述是小編給大家介紹的在AngularJS中如何使用谷歌地圖把當前位置顯示出來的相關知識,希望對大家有所幫助。

相關文章

最新評論

凌海市| 建水县| 太湖县| 宁国市| 乡城县| 称多县| 全州县| 阿巴嘎旗| 厦门市| 襄城县| 中西区| 桐乡市| 通榆县| 靖远县| 福安市| 桐梓县| 明星| 江都市| 巴楚县| 南皮县| 维西| 井研县| 南乐县| 陇川县| 中山市| 佳木斯市| 邵阳县| 大同市| 黑河市| 榆社县| 阿克陶县| 从化市| 日照市| 金山区| 洞口县| 西乡县| 乡宁县| 香港| 房产| 台前县| 安陆市|