|

楼主 |
发表于 2018-9-28 18:56:40
|
显示全部楼层
- var me = this;
- function successCallback(position) {
- var lat = position.coords.latitude;//获取到纬度
- var lon = position.coords.longitude;//获取到经度
-
- var url = 'https://api.map.baidu.com/geocoder/v2/?ak=(这里填写一个key,需要去百度地图API申请一个key)&callback=renderReverse&location=' + lat + ',' + lon + '&output=json&pois=1';
- $.ajax({
- url : url,
- dataType : 'jsonp',
- processData : false,
- type : 'get',
- success : function(data) {
- alert(data.result.formatted_address);
- // 将获取到的定位信息,设置到output上显示
- var addtext = data.result.formatted_address;
- me.comp("output1").set("value", addtext);
- },
- error : function(XMLHttpRequest, textStatus, errorThrown) {
- alert(textStatus + "---");
- }
- });
- }
- function errorCallback(position) {
- alert("失败");
- }
-
- navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
复制代码
用的是这个方法,没用到watch方法也要调用clearwatch吗 |
|