ionic ngcordova map 地圖
幾乎每個APP都會有地圖 所以在這裏記錄一下
1.在index.html 中
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB16sGmIekuGIvYOfNoW9T44377IU2d2Es&sensor=true"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="lib/ionic/js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>
2. CSS
map {
display: block;
width: 100%;
height: 100%;
}
.scroll {
height: 100%;
}
3. 生成一個指令
.directive('map', function() {
return {
restrict: 'E',
scope: {
onCreate: '&'
},
link: function ($scope, $element, $attr) {
function initialize() {
var mylang=new google.maps.LatLng(43.07493, -89.381388);
var mapOptions = {
center: mylang,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map($element[0], mapOptions);
//Marker + infowindow + angularjs compiled ng-click
var marker = new google.maps.Marker({
position: mylang,
map: map,
title: 'Uluru (Ayers Rock)'
});
var infowindow = new google.maps.InfoWindow({
content:"Hello World!"
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
$scope.onCreate({map: map});
//Stop the side bar from dragging when mousedown / tapdown on the map
google.maps.event.addDomListener($element[0], 'mousedown', function (e) {
e.preventDefault();
return false;
});
}
if (document.readyState === "complete") {
initialize();
} else {
google.maps.event.addDomListener(window, 'load', initialize);
}
}
}
});
4.在index.html 中寫入 map 標籤 <map on-create="mapCreated(map)"></map>
5.設置控制器
.controller('MapCtrl', function($scope, $ionicLoading, $cordovaGeolocation) {
$scope.mapCreated = function(map) {
$scope.map = map;
};
$scope.centerOnMe = function() {
console.log("Centering");
if (!$scope.map) {
return;
}
$scope.loading = $ionicLoading.show({
content: 'Getting current location...',
showBackdrop: false
});
$cordovaGeolocation
.getCurrentPosition()
.then(function(pos) {
var lat = pos.coords.latitude
var long = pos.coords.longitude
console.log('Got pos', pos);
$scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));//
var marker=new google.maps.Marker({
map: $scope.map,
position: new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude)
});//這個marker 設置了一下
$scope.loading.hide();
}, function(err) {
// error
});
// navigator.geolocation.getCurrentPosition(function (pos) {
// console.log('Got pos', pos);
// $scope.map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
// var marker=new google.maps.Marker({
// map: $scope.map,
// position: new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude)
// });
// $scope.loading.hide();
// }, function (error) {
// alert('Unable to get location: ' + error.message);
// });
};
});
6. 忘記了...為了更加的準確 還是添加了ngcordova plugin 插件
cordova plugin add org.apache.cordova.geolocation 不要忘記了注入 ngCordova$cordovaGeolocation
ionic ngcordova map 地圖的更多相关文章
- ionic ngcordova camera
拍照是經常用到的,所以記錄一下 拍照的代碼... 1. ionic start camera blankcd camera ionic platform add ios 2. 添加插件,這裏很熟悉.. ...
- ionic ngCordova插件安装
ngCordova的安装配置 官网提供了两种安装的方法: 1. 使用bower来安装 2. 下载zip文件 推荐使用bower安装,在使用bower之前,我们电脑中需要先配置bower.bower的配 ...
- ionic ngcordova barcodescanner
二維碼掃描 最近有一個項目用到了 二維碼的掃描 總結一下 記錄一下 1. ionic platform add ios 2. 添加插件 cordova plugin add https://gi ...
- ionic使用方法
windows下安装配置 npm install -g ionic npm install -g cordova ionic start myproject cd myproject ionic pl ...
- ionic实现双击返回键退出功能
实现这个功能需要四个步骤: 步骤一: 说明:因为需要和手机的硬件(返回按钮)打交道,而ionic本身是不具备该功能的,但是有一个东西可以:ng-cordova插件,这个插件是phoneGap为了能让i ...
- Ionic开发实战
转自:http://blog.csdn.net/i348018533/article/details/47258449/ 折磨的两个月!Ionic从零单排,到项目发布!遇到了很多问题但都一一解决了,此 ...
- 170多个Ionic Framework学习资源(转载)
在Ionic官网找到的学习资源:http://blog.ionic.io/learning-ionic-in-your-living-room/ 网上的文章比较多,但是很多时候我们很难找到自己需要的. ...
- ionic 通过下载apk升级App
上篇通过更新文件升级APP,如果遇到了比如更新插件之类的问题,上篇是无法解决的,所以为了解决这个问题,需要下载apk文件升级APP. 1.配置文件如下:{'appVersion':'1.0.0', ...
- ionic cordova social media sharing plugin
https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git 从上面的连接下载 插件 1.肯定是要加入 下面的那个文件的吖 从 ...
随机推荐
- ADF_Database Develop系列1_通过UML数据库开发之建Logical UML Class Model
2013-05-01 Created By BaoXinjian
- DBA_Oracle数据库运维监控(案例)
2014-07-27 Created By BaoXinjian
- PLSQL_闪回删除FlashBack Delete表误删除如何进行恢复(案例)
2014-07-02 Created By BaoXinjian
- android js调试
http://blog.allenm.me/ 其他平台去这篇文章看 //js调试调试功能支持4.4版本以上的 if(Build.VERSION.SDK_INT >= Build.VERSION_ ...
- webuploader在同一个页面支持多个按钮实例
之前在时候用到webuploader ,起初是支持单实例,后来要求支持多实例. webuploder API网址,如果不懂我说的可以去查看http://fex.baidu.com/webuploade ...
- python 抓取javascript 动态数据
1. 新安装一个python库 :~$ sudo pip install seleniumhq 2. 编写代码: 以获取百度百科点赞数为例 import selenium from selenium ...
- Java线程新特性--- Lock
在Java5中,专门提供了锁对象,利用锁可以方便的实现资源的封锁,用来控制对竞争资源并发访问的控制,这些内容主要集中在java.util.concurrent.locks包下面,里面有三个重要的接口C ...
- javascript代码注意事项
1 代码行末要加分好.原因<<javascript高级程序设计第三版21页第三行>> 2 初始化变量应该加上默认值因为使用typeof时 未声明和声明为初始化的值都返回unde ...
- oracle10g如何配置客户端
http://jingyan.baidu.com/article/4d58d541c108939dd4e9c0f5.html 不行的话: 对tnsnames.ora进行编辑:ORCL = (DESCR ...
- spring应用于web项目中
目标: 在webapp启动的时候取到spring的applicationContext对象,并把applicationContext对象存到servletContext里面,在需要的时候直接从serv ...