zoukankan      html  css  js  c++  java
  • 定位功能

    geo.js:

    var GPS = {

    // 定位

    geolocation: function(okFn, errFn){

    var me = this;

    if(navigator.geolocation){

    navigator.geolocation.getCurrentPosition(function(r){

    if(!r || !r.coords){

    typeof errFn == "function" && errFn(err);

    return;

    }

    console.log(r);

    var lat = r.coords.latitude;

    var lon = r.coords.longitude;

    var url = 'https://api.map.baidu.com/geocoder/v2/?coordtype=*******&ak=*********&callback=_callback&location=' + (lat + ',' + lon) + '&output=json&pois=0';

    $.ajax({

    url: url,

    type: "POST",

    dataType: 'jsonp',

    success: function(res) {

    typeof okFn == "function" && okFn(res.result);

    console.log('geo success')

    },

    error: function(err){

    console.log('geo error')

    typeof errFn == "function" && errFn(err);

    }

    });

      }, function() {

      location.assign('city.html' + location.search);

      });

        }else{

        typeof errFn == "function" && errFn(err);

        }

        var obj = JSON.parse(window.sessionStorage.getItem("cityItem"));

        console.log(obj);

    }

    }

    export default GPS;

    调用:

    GPS.geolocation(

                        function (res) {

            //successFun 

                           console.log('baidudingwei', res);

                        let _province = res.addressComponent.province,

                            _city = res.addressComponent.city;

                        //特殊城市规则化

                        let filterProvince = ["上海市", "北京市", "天津市", "重庆市"];

                        if (filterProvince.indexOf(_province) != -1) {

                            _province = _province.substring(0, _province.length - 1);

                        }

                        

                        },

                        function () {

                            //errFun

                        }

                    );

  • 相关阅读:
    LeetCode:35. 搜索插入位置
    LeetCode:34. 在排序数组中查找元素的第一个和最后一个位置
    LeetCode:33. 搜索旋转排序数组
    LeetCode:31. 下一个排列
    LeetCode:23. 合并K个排序链表
    LeetCode:21. 合并两个有序链表
    JDE910笔记1--基础介绍及配置[转]
    JDE910笔记2--OMW项目建立及简单使用[转]
    活动目录—远程安装额外域控制器[转]
    java入门第五步之数据库项目实战【转】
  • 原文地址:https://www.cnblogs.com/Super-scarlett/p/9224201.html
Copyright © 2011-2022 走看看