使用html5 地理位置技术 和 百度地图api查询当前位置
使用了 zepto 和 requirejs
define(['zepto'],function($){
var geolocation = {
init:function(config,onSuccess,onError){
if(typeof(config)=='function'){
onError = onSuccess;
onSuccess = config;
config = undefined;
}
if(Object(config)===config){
for(var k in this.option){
this.option[k] = config[k];
}
}
if(typeof(onSuccess)=='function'){
this.onSuccess = onSuccess;
}
if(typeof(onError)=='function'){
this.onError = onError;
}
return this;
},
getPosition:function(returnType){//returnType==cityName,返回城市名称
var host = this;
navigator.geolocation.getCurrentPosition(function ( position){
console.log('getCurrentPosition success ',position);
if(!returnType){
host.onSuccess.call(null,position);
}else{
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var urls="http://api.map.baidu.com/geocoder/v2/?ak=0QoBGmQ4i5N0FycRCQMukgqd&callback=renderReverse&location="+lat+","+lng+"8&output=json&pois=0";
$.ajax({
type: "POST",
url: urls,
dataType : "jsonp",
success: function(data){
//alert(JSON.stringify(data));
//alert(host.onSuccess)
console.log('get city name>>>',data);
host.onSuccess.call(null,data);
},
error:function(error){
host.onError.call(null,error);
}
});
}
}, function(error){
host.onError.call(null,error);
}, this.option);
return this;
},
option:{
enableHighAccuracy: true,
maximumAge: 30000,
timeout: 20000
},
onSuccess: function(data){
console.log('geolocation.getCurrentPosition success:',data);
},
onError:function(error){
console.log('geolocation.getCurrentPosition error:',error);
}
};
return geolocation;
});
使用html5 地理位置技术 和 百度地图api查询当前位置的更多相关文章
- HTML5页面直接调用百度地图API,获取当前位置,直接导航目的地
<!DOCTYPE html> <html lang="zh-cmn-Hans"> <meta charset="UTF-8"&g ...
- HTML5调用百度地图API获取当前位置并直接导航目的地的方法
<!DOCTYPE html> <html lang="zh-cmn-Hans"> <meta charset="UTF-8&quo ...
- 【地图功能开发系列:二】根据地址名称通过百度地图API查询出坐标
根据地址名称通过百度地图API查询出坐标 百度地图ApiUrl string url = "http://api.map.baidu.com/geocoder?address={0}& ...
- 网页百度地图api,支持位置偏移
网页百度地图api,支持位置偏移 需加载 jq <style type="text/css"> #allmap {width:100%; height:100%; bo ...
- HTML5地理定位,百度地图API,知识点熟悉
推断浏览器的兼容问题: IE9+支持地理定位,FF Chrome新版支持地理定位 if (navigator.geolocation) { alert('支持地理定位'); } e ...
- 百度地图API定位+显示位置
1. 先在需要嵌入地图的页面引入map.js <script src="http://api.map.baidu.com/api?v=2.0&ak=你的秘钥"> ...
- 通过百度地图API显示当前位置在地图上(图标显示)--第三方开源--百度地图(二)
1.下载百度地图的demo,下载地址:http://lbsyun.baidu.com/sdk/download?selected=mapsdk_basicmap,mapsdk_searchfuncti ...
- html5移动端根据百度地图api获取详细地址
<script type="text/javascript" src="js/BMap.js" ></script> <scrip ...
- 用百度地图API分析打交通大数据
百度地图API, 文档不全,例子不细致. 在网上还没有太多有用的例子.比如说下面几个需求的解决方案就找不到: 1. 如何用百度地图API查询一个地点的经纬度. 2. 如何用百度地图通过一个经纬度查询商 ...
随机推荐
- url带#号,微信支付那些坑
现在前端很多框架的前端路由都带#号,主要为了做到无刷新跳转页面. 在微信公众号做微信支付时,配置的支付路径比如是http://www.eee.com/#/order,在调微信支付的方法时错误信息是'U ...
- android 任意类 获得屏幕大小
方法一 WindowManager managet=(WindowManager) context.getSystemService(Context.WINDOW_SERVICE); Display ...
- pngcrush caught libpng error: Not a PNG file..
今日真机测试遇到这样的奇葩问题: While reading XXX/XXX.png pngcrush caught libpng error: Not a PNG file.. 替换几次图片都没解决 ...
- C# 操作excel单元格居中
C# 操作excel //导出Excel private void ExportExcel(string fileName, System.Data.DataTable myDGV, s ...
- C++获取当前目录
/* @author:CodingMengmeng @theme:C++获取当前目录 @time:2017-1-6 21:03:34 @blog:http://www.cnblogs.com/codi ...
- 远程CDN加速不可用,加载本地库
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery ...
- for_each(c++11)
http://www.cplusplus.com/reference/algorithm/for_each/ template<class InputIterator, class Functi ...
- 获取json数据
通过异步获取json来展示数据表格,性能提高不少.实例如下: 前台: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999 ...
- 分割一个表到多个实体<EntityFramework6.0>
声明方式 public class Photograph { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public in ...
- F#之旅3 - F# PK C#:简单的求和
原文链接:https://swlaschin.gitbooks.io/fsharpforfunandprofit/content/posts/fvsc-sum-of-squares.html Comp ...