实例一:

var AMapArea=document.getElementById('amap');
AMapArea.parentNode.style.height="100%";
//$scope.AMapId='container';
$scope.mapObj;//存放初始化的地图对象
//$scope.initAMap=function(){
var position=new AMap.LngLat(116.397428,39.90923);
$scope.mapObj=new AMap.Map("container",{
resizeEnable: true,
zoom: 14,
center: [116.39,39.9]
});
$scope.mapObj.plugin(['AMap.Geolocation'], function () {
var geolocation = new AMap.Geolocation({
enableHighAccuracy: true,//是否使用高精度定位,默认:true
timeout: 10000, //超过10秒后停止定位,默认:无穷大
maximumAge: 0, //定位结果缓存0毫秒,默认:0
convert: true, //自动偏移坐标,偏移后的坐标为高德坐标,默认:true
showButton: true, //显示定位按钮,默认:true
buttonPosition: 'LB', //定位按钮停靠位置,默认:'LB',左下角
buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量,默认:Pixel(10, 20)
showMarker: true, //定位成功后在定位到的位置显示点标记,默认:true
showCircle: true, //定位成功后用圆圈表示定位精度范围,默认:true
panToLocation: true, //定位成功后将定位到的位置作为地图中心点,默认:true
zoomToAccuracy:true //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
});
$scope.mapObj.addControl(geolocation);
AMap.event.addListener(geolocation, 'complete', onComplete);//返回定位信息
AMap.event.addListener(geolocation, 'error', onError); //返回定位出错信息
});
function onComplete(dt)
{
var position=dt.position;
var _latitude = position.getLat();
var _longitude = position.getLng();
$scope.mapObj.setCenter([_longitude,_latitude]);
console.log(_latitude,_longitude);
}

实例二、

function getLocation() {
var deferred = $q.defer(); if (!navigator.geolocation)
{
console.log("不支持");
return;
}
console.log("start");;
navigator.geolocation.getCurrentPosition(function (position) {
var _locationGaps = [];
console.log("ok");
var _latitude = position.coords.latitude;
var _longitude = position.coords.longitude;
$scope.mapObj.setCenter([_longitude,_latitude]);
console.log(_latitude,_longitude); }, function (error) {
switch(error.code)
{
case error.PERMISSION_DENIED:
console.log("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
console.log("Location information is unavailable.");
break;
case error.TIMEOUT:
console.log("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
console.log("An unknown error occurred.");
break;
}
// 如果获取经纬度时出错, 提示错误
//toaster.pop('error','无法获取您的地理位置','请检查您是否禁止本应用获取您的当前位置');
console.log('无法获取您的地理位置','请检查您是否禁止本应用获取您的当前位置');
deferred.reject(error);
});
return deferred.promise;
};

实例三、

function getLocation1() {

      navigator.geolocation.getCurrentPosition(onSuccess, onError, { maximumAge: 3000, timeout: 5000, enableHighAccuracy: true });
function onSuccess(position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
$scope.mapObj.setCenter([lat,long]);
console.log(lat,long);
//appvalues.showmessage("已经成功定位.");
}
function onError(err) {
//appvalues.showmessage("无法获取地理位置.");
console.log("无法获取地理位置.");
console.log(JSON.stringify(err));
return;
}
//获取地理位置
/*document.addEventListener("deviceready", function (success) {
var posOptions = { timeout: 5000, enableHighAccuracy: false };
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function (position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
$scope.mapObj.setCenter([lat,long]);
console.log(lat,long);
//appvalues.showmessage("已经成功定位.");
}, function (err) {
//appvalues.showmessage("无法获取地理位置.");
console.log("无法获取地理位置.");
console.log(JSON.stringify(err));
return;
});
}, false);*/
};

160913、ionic + 高德地图定位的更多相关文章

  1. 高德地图定位不到 报错 location Error, ErrCode:7, errInfo:KEY错误 请到http://lbs.amap.com/api/android-location-sdk/abouterrorcode/查看错误码说明.

    出现该问题的可能是高德地图的配置不准确: 仔细配对一下 看sha1 是否是通过应用签名生成的  要区分发布版的sha1 跟调试版的sha1  是不相同的 (小编我第一次反这种错误的时候 是因为我把高得 ...

  2. android开发对应高德地图定位服务进度一

    进行android的高德地图开发首先需要进入高德地图的控制台进行注册登录.之后创建新的应用并且绑定软件得到相应的key. 这里面需要找到自己软件对应的多个SHA1.这里有发布版和调试版,以及对应的软件 ...

  3. ionic 添加地图定位功能

    由于项目需求,需要一个定位功能,通过google或百度,搜到一个cordova-plugin-geolocation的插件,在ios上可以用,但是在android就呵呵了,原因就不说了,大家都知道.所 ...

  4. Android 高德地图定位

    创建Key 打开高德开发平台 → 我的应用 → 创建应用 → 创建新Key 说明: 1.发布版安全码获取:用自己的签名打包成apk安装软件,用SHA1工具查看 2.调试版安全码获取: 直接运行安装软件 ...

  5. Android开发实现高德地图定位

    1.获取Key 参考官方文档:http://lbs.amap.com/api/android-location-sdk/guide/create-project/get-key 对于签名文件的获取建议 ...

  6. 高德地图定位api以及导航和定位 位置的偏差

    <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.2&key=37 ...

  7. Flutter 使用高德地图定位

    amap_location 包 获取debug SHA1 // 使用debug.keystore获取debug SHA1 C:\Users\ajanuw\.android>keytool -li ...

  8. 高德,百度,Google地图定位偏移以及坐标系转换

    一.在进行地图开发过程中,我们一般能接触到以下三种类型的地图坐标系: 1.WGS-84原始坐标系 一般用国际GPS纪录仪记录下来的经纬度,通过GPS定位拿到的原始经纬度,Google和高德地图定位的的 ...

  9. 安卓---高德地图API应用

    说明:定位需要导入android_location 的jar包,如果没有会报错,这个官方网站好像找不到,这是我在网上找到的一个链接 http://download.csdn.net/detail/ra ...

随机推荐

  1. LeetCode Inorder Successor in BST

    原题链接在这里:https://leetcode.com/problems/inorder-successor-in-bst/ Given a binary search tree and a nod ...

  2. 目标检测的图像特征提取之(一)HOG特征

    http://blog.csdn.net/liulina603/article/details/8291093

  3. BI系统规划前需要准备的6项工作

    通常在进行商业智能信息系统项目之前,可以先从明确经营分析的愿景和目的入手,确定分析方法和工具.设计经营分析框架.设计指标和报表.IT实现和持续改进机制建立等几个步骤,即先有经营分析体系再有商业智能.第 ...

  4. H3C Series Router MSR26-00与F3736 VPN IP SEC

    注:建立链接之后经常断线,需要两边进行PING通才可以.待解决.

  5. Sublime text 3 SVN插件及使用方法

    前提是你电脑里已装有SVN,这时只是设置快捷调用SVN. 1.通过快捷键 ctrl+` 或者 View > Show Console 菜单打开控制台 2.粘贴对应版本的代码后回车安装 适用于 S ...

  6. iOS 归档

    #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...

  7. iOS NSUserDefaults的基本使用

    /** * NSUserDefaults可以进行轻量级的数据存储 * NSUserDefaults支持的数据类型: NSString, NSNumber, NSDate, NSArray, * NSD ...

  8. uiwebview加载中文URL

    uiwebview加载中文URL _paperGamePath = [_paperGamePath stringByAddingPercentEscapesUsingEncoding:NSUTF8St ...

  9. [转]MySQL数据库引擎介绍、区别、创建和性能测试的深入分析

    本篇文章是对MySQL数据库引擎介绍.区别.创建和性能测试进行了详细的分析介绍,需要的朋友参考下   数据库引擎介绍 MySQL数据库引擎取决于MySQL在安装的时候是如何被编译的.要添加一个新的引擎 ...

  10. 去掉字符串中的空格 JS JQ 正则三种不同写法

    <script> function trim(str) { return str.replace(/(^\s*|\s*$)/g, "") } console.log(t ...