草庐IT

uni-app 微信小程序调用高德地图

奋斗的小岛ssnnyy 2023-05-01 原文

1、使用uni-app内置的map组件map | uni-app官网

2、去高德地图申请key,然后下载所需要的插件,详见入门指南-微信小程序插件 | 高德地图API

3、上代码

下载amap-wx.js 文件后需要修改一下代码:

function AMapWX(a) {
    this.key = a.key, this.requestConfig = {
        key: a.key,
        s: "rsx",
        platform: "WXJS",
        appname: a.key,
        sdkversion: "1.2.0",
        logversion: "2.0"
    }
}
AMapWX.prototype.getWxLocation = function(a, b) {
    uni.getLocation({
        type: "gcj02",
        success: function(a) {
            var c = a.longitude + "," + a.latitude;
            uni.setStorage({
                key: "userLocation",
                data: c
            }), b(c)
        },
        fail: function(c) {
            uni.getStorage({
                key: "userLocation",
                success: function(a) {
                    a.data && b(a.data)
                }
            }), a.fail({
                errCode: "0",
                errMsg: c.errMsg || ""
            })
        }
    })
}, AMapWX.prototype.getRegeo = function(a) {
    function c(c) {
        var d = b.requestConfig;
        uni.request({
            url: "https://restapi.amap.com/v3/geocode/regeo",
            data: {
                key: b.key,
                location: c,
                extensions: "all",
                s: d.s,
                platform: d.platform,
                appname: b.key,
                sdkversion: d.sdkversion,
                logversion: d.logversion
            },
            method: "GET",
            header: {
                "content-type": "application/json"
            },
            success: function(b) {
                var d, e, f, g, h, i, j, k, l;
                b.data.status && "1" == b.data.status ? (d = b.data.regeocode, e = d.addressComponent, f = [], g = "", d && d.roads[
                        0] && d.roads[0].name && (g = d.roads[0].name + "附近"), h = c.split(",")[0], i = c.split(",")[1], d.pois && d
                    .pois[0] && (g = d.pois[0].name + "附近", j = d.pois[0].location, j && (h = parseFloat(j.split(",")[0]), i =
                        parseFloat(j.split(",")[1]))), e.provice && f.push(e.provice), e.city && f.push(e.city), e.district && f.push(
                        e.district), e.streetNumber && e.streetNumber.street && e.streetNumber.number ? (f.push(e.streetNumber.street),
                        f.push(e.streetNumber.number)) : (k = "", d && d.roads[0] && d.roads[0].name && (k = d.roads[0].name), f.push(
                        k)), f = f.join(""), l = [{
                        iconPath: a.iconPath,
                        width: a.iconWidth,
                        height: a.iconHeight,
                        name: f,
                        desc: g,
                        longitude: h,
                        latitude: i,
                        id: 0,
                        regeocodeData: d
                    }], a.success(l)) : a.fail({
                    errCode: b.data.infocode,
                    errMsg: b.data.info
                })
            },
            fail: function(b) {
                a.fail({
                    errCode: "0",
                    errMsg: b.errMsg || ""
                })
            }
        })
    }
    var b = this;
    a.location ? c(a.location) : b.getWxLocation(a, function(a) {
        c(a)
    })
}, AMapWX.prototype.getWeather = function(a) {
    function d(d) {
        var e = "base";
        a.type && "forecast" == a.type && (e = "all"), uni.request({
            url: "https://restapi.amap.com/v3/weather/weatherInfo",
            data: {
                key: b.key,
                city: d,
                extensions: e,
                s: c.s,
                platform: c.platform,
                appname: b.key,
                sdkversion: c.sdkversion,
                logversion: c.logversion
            },
            method: "GET",
            header: {
                "content-type": "application/json"
            },
            success: function(b) {
                function c(a) {
                    var b = {
                        city: {
                            text: "城市",
                            data: a.city
                        },
                        weather: {
                            text: "天气",
                            data: a.weather
                        },
                        temperature: {
                            text: "温度",
                            data: a.temperature
                        },
                        winddirection: {
                            text: "风向",
                            data: a.winddirection + "风"
                        },
                        windpower: {
                            text: "风力",
                            data: a.windpower + "级"
                        },
                        humidity: {
                            text: "湿度",
                            data: a.humidity + "%"
                        }
                    };
                    return b
                }
                var d, e;
                b.data.status && "1" == b.data.status ? b.data.lives ? (d = b.data.lives, d && d.length > 0 && (d = d[0], e = c(
                    d), e["liveData"] = d, a.success(e))) : b.data.forecasts && b.data.forecasts[0] && a.success({
                    forecast: b.data.forecasts[0]
                }) : a.fail({
                    errCode: b.data.infocode,
                    errMsg: b.data.info
                })
            },
            fail: function(b) {
                a.fail({
                    errCode: "0",
                    errMsg: b.errMsg || ""
                })
            }
        })
    }

    function e(e) {
        uni.request({
            url: "https://restapi.amap.com/v3/geocode/regeo",
            data: {
                key: b.key,
                location: e,
                extensions: "all",
                s: c.s,
                platform: c.platform,
                appname: b.key,
                sdkversion: c.sdkversion,
                logversion: c.logversion
            },
            method: "GET",
            header: {
                "content-type": "application/json"
            },
            success: function(b) {
                var c, e;
                b.data.status && "1" == b.data.status ? (e = b.data.regeocode, e.addressComponent ? c = e.addressComponent.adcode :
                    e.aois && e.aois.length > 0 && (c = e.aois[0].adcode), d(c)) : a.fail({
                    errCode: b.data.infocode,
                    errMsg: b.data.info
                })
            },
            fail: function(b) {
                a.fail({
                    errCode: "0",
                    errMsg: b.errMsg || ""
                })
            }
        })
    }
    var b = this,
        c = b.requestConfig;
    a.city ? d(a.city) : b.getWxLocation(a, function(a) {
        e(a)
    })
}, AMapWX.prototype.getPoiAround = function(a) {
    function d(d) {
        var e = {
            key: b.key,
            location: d,
            s: c.s,
            platform: c.platform,
            appname: b.key,
            sdkversion: c.sdkversion,
            logversion: c.logversion
        };
        a.querytypes && (e["types"] = a.querytypes), a.querykeywords && (e["keywords"] = a.querykeywords), uni.request({
            url: "https://restapi.amap.com/v3/place/around",
            data: e,
            method: "GET",
            header: {
                "content-type": "application/json"
            },
            success: function(b) {
                var c, d, e, f;
                if (b.data.status && "1" == b.data.status) {
                    if (b = b.data, b && b.pois) {
                        for (c = [], d = 0; d < b.pois.length; d++) e = 0 == d ? a.iconPathSelected : a.iconPath, c.push({
                            latitude: parseFloat(b.pois[d].location.split(",")[1]),
                            longitude: parseFloat(b.pois[d].location.split(",")[0]),
                            iconPath: e,
                            width: 22,
                            height: 32,
                            id: d,
                            name: b.pois[d].name,
                            address: b.pois[d].address
                        });
                        f = {
                            markers: c,
                            poisData: b.pois
                        }, a.success(f)
                    }
                } else a.fail({
                    errCode: b.data.infocode,
                    errMsg: b.data.info
                })
            },
            fail: function(b) {
                a.fail({
                    errCode: "0",
                    errMsg: b.errMsg || ""
                })
            }
        })
    }
    var b = this,
        c = b.requestConfig;
    a.location ? d(a.location) : b.getWxLocation(a, function(a) {
        d(a)
    })
}, AMapWX.prototype.getStaticmap = function(a) {
    function f(b) {
        c.push("location=" + b), a.zoom && c.push("zoom=" + a.zoom), a.size && c.push("size=" + a.size), a.scale && c.push(
                "scale=" + a.scale), a.markers && c.push("markers=" + a.markers), a.labels && c.push("labels=" + a.labels), a.paths &&
            c.push("paths=" + a.paths), a.traffic && c.push("traffic=" + a.traffic);
        var e = d + c.join("&");
        a.success({
            url: e
        })
    }
    var e, b = this,
        c = [],
        d = "https://restapi.amap.com/v3/staticmap?";
    c.push("key=" + b.key), e = b.requestConfig, c.push("s=" + e.s), c.push("platform=" + e.platform), c.push("appname=" +
            e.appname), c.push("sdkversion=" + e.sdkversion), c.push("logversion=" + e.logversion), a.location ? f(a.location) :
        b.getWxLocation(a, function(a) {
            f(a)
        })
}, AMapWX.prototype.getInputtips = function(a) {
    var b = this,
        c = b.requestConfig,
        d = {
            key: b.key,
            s: c.s,
            platform: c.platform,
            appname: b.key,
            sdkversion: c.sdkversion,
            logversion: c.logversion
        };
    a.location && (d["location"] = a.location), a.keywords && (d["keywords"] = a.keywords), a.type && (d["type"] = a.type),
        a.city && (d["city"] = a.city), a.citylimit && (d["citylimit"] = a.citylimit), uni.request({
            url: "https://restapi.amap.com/v3/assistant/inputtips",
            data: d,
            method: "GET",
            header: {
                "content-type": "application/json"
            },
            success: function(b) {
                b && b.data && b.data.tips && a.success({
                    tips: b.data.tips
                })
            },
            fail: function(b) {
                a.fail({
                    errCode: "0",
                    errMsg: b.errMsg || ""
                })
            }
        })
}, AMapWX.prototype.getDrivingRoute = function(a) {
    var b = this,
        c = b.requestConfig,
        d = {
            key: b.key,
            s: c.s,
            platform: c.platform,
            appname: b.key,
            sdkversion: c.sdkversion,
            logversion: c.logversion
        };
    a.origin && (d["origin"] = a.origin),
        a.destination && (d["destination"] = a.destination),
        a.strategy && (d["strategy"] = a.strategy),
        a.waypoints && (d["waypoints"] = a.waypoints),
        a.avoidpolygons && (d["avoidpolygons"] = a.avoidpolygons),
        a.avoidroad && (d["avoidroad"] = a.avoidroad),
        uni.request({
            url: "https://restapi.amap.com/v3/direction/driving",
            data: d,
            method: "GET",
            header: {
                "content-type": "application/json"
            },
            success: function(b) {
                b && b.data && b.data.route && a.success({
                    paths: b.data.route.paths,
                    taxi_cost: b.data.route.taxi_cost || ""
                })
            },
            fail: function(b) {
                a.fail({
                    errCode: "0",
                    errMsg: b.errMsg || ""
                })
            }
        })
}, AMapWX.prototype.getWalkingRoute = function(a) {
    var b = this,
        c = b.requestConfig,
        d = {
            key: b.key,
            s: c.s,
            platform: c.platform,
            appname: b.key,
            sdkversion: c.sdkversion,
            logversion: c.logversion
        };
    a.origin && (d["origin"] = a.origin), a.destination && (d["destination"] = a.destination), uni.request({
        url: "https://restapi.amap.com/v3/direction/walking",
        data: d,
        method: "GET",
        header: {
            "content-type": "application/json"
        },
        success: function(b) {
            b && b.data && b.data.route && a.success({
                paths: b.data.route.paths
            })
        },
        fail: function(b) {
            a.fail({
                errCode: "0",
                errMsg: b.errMsg || ""
            })
        }
    })
}, AMapWX.prototype.getTransitRoute = function(a) {
    var b = this,
        c = b.requestConfig,
        d = {
            key: b.key,
            s: c.s,
            platform: c.platform,
            appname: b.key,
            sdkversion: c.sdkversion,
            logversion: c.logversion
        };
    a.origin && (d["origin"] = a.origin), a.destination && (d["destination"] = a.destination), a.strategy && (d[
        "strategy"] = a.strategy), a.city && (d["city"] = a.city), a.cityd && (d["cityd"] = a.cityd), uni.request({
        url: "https://restapi.amap.com/v3/direction/transit/integrated",
        data: d,
        method: "GET",
        header: {
            "content-type": "application/json"
        },
        success: function(b) {
            if (b && b.data && b.data.route) {
                var c = b.data.route;
                a.success({
                    distance: c.distance || "",
                    taxi_cost: c.taxi_cost || "",
                    transits: c.transits
                })
            }
        },
        fail: function(b) {
            a.fail({
                errCode: "0",
                errMsg: b.errMsg || ""
            })
        }
    })
}, AMapWX.prototype.getRidingRoute = function(a) {
    var b = this,
        c = b.requestConfig,
        d = {
            key: b.key,
            s: c.s,
            platform: c.platform,
            appname: b.key,
            sdkversion: c.sdkversion,
            logversion: c.logversion
        };
    a.origin && (d["origin"] = a.origin), a.destination && (d["destination"] = a.destination), uni.request({
        url: "https://restapi.amap.com/v4/direction/bicycling",
        data: d,
        method: "GET",
        header: {
            "content-type": "application/json"
        },
        success: function(b) {
            b && b.data && b.data.data && a.success({
                paths: b.data.data.paths
            })
        },
        fail: function(b) {
            a.fail({
                errCode: "0",
                errMsg: b.errMsg || ""
            })
        }
    })
}, module.exports.AMapWX = AMapWX;
 

视图:

<view class="el-vue-search-box-container">
             <view class="section-search">
               <input placeholder="请输入" v-model="searchValue" type="text" @input="searchMap"></input><span class="search-btn" @tap="searchCurrentLocation">搜索</span>
             </view>
            <view class="search-tips" v-if="searchList.length>0 && isShowSearchList">
                <ul>
                    <li @tap="getCurrentSingleLocation(item)" v-for="item in searchList">{{item.name}}</li>
                </ul>
            </view>
         </view>
         
        <view class="content" style="width:100%;height: 80%;">
            <map class="map" id="map" :latitude="latitude" :longitude="longitude" scale="18" show-location="true"
                :markers="markers" @tap="getCurrentLocation"></map>        
        </view>
        <view class="address">您选择的地址是:{{ addressMap }}</view>
        <u-button style="position: fixed; left: 0; bottom: 3px; width: 100%" type="primary" @click="submit()">确 定
        </u-button>

页面引用并使用

import amap from '@/libs/amap-wx.js';
export default {
    data(){
       return{
            addressMap: "",
            searchValue: "",
            markers: [], 
            amapPlugin: null,
            key: '', //高德地图key
            latitude: '',
            longitude: '',
            regeocodeData:{},
            searchList:[],
            isShowSearchList:false,
        }
    },
    mounted() {
            this.init();
        },
        methods: {
            init() {
                this.amapPlugin = new amap.AMapWX({
                    key: this.key
                });
                this.amapPlugin.getRegeo({
                    success: (data) => {
                        this.latitude = data[0].latitude;
                        this.longitude = data[0].longitude;
                        this.markers = [
                            {
                                id:1,
                                longitude: data[0].longitude,
                                latitude: data[0].latitude,
                                iconPath:'../../static/img/mark_bs.png',
                                width:35,  
                                height:50
                            }
                        ]
                        this.addressMap = data[0].regeocodeData.formatted_address;
                        this.regeocodeData = data[0].regeocodeData
                        uni.hideLoading();
                    },
                    fail: (info)=> {
                        //失败回调
                        console.log("getRegeo", info)
                    }
                });
            },
            //点击地图
            getCurrentLocation(e) {
                //console.log(e);
                /* 更新地图中心点位 start */
                this.latitude = e.detail.latitude;
                this.longitude = e.detail.longitude;
                /* 更新地图中心点位 end */
                this.markers = [
                    {
                        id:1,
                        longitude: e.detail.longitude,
                        latitude: e.detail.latitude,
                        iconPath:'../../static/img/mark_bs.png',
                        width:35,
                        height:50
                    }
                ]
                let coordinate = e.detail.longitude + "," + e.detail.latitude;
                this.amapPlugin.getRegeo({
                    iconPathSelected: '../../static/img/mark_bs.png', //如:..­/..­/img/marker_checked.png
                    location:coordinate,
                    success: (data) => {
                        //console.log(data)
                        //this.addressName = data[0].name;  
                        this.addressMap = data[0].regeocodeData.formatted_address;
                        this.regeocodeData = data[0].regeocodeData
                    },
                    fail: (info)=> {
                        //失败回调
                        console.log("getRegeo", info)
                    }
                });
            },
            //搜索关键字
            searchMap(){
                this.amapPlugin.getInputtips({
                    key: this.key,
                    keywords: this.searchValue,
                    location: this.longitude + ',' + this.latitude,
                    success: (data) => {
                        //console.log(data);
                        this.searchList = data.tips;
                        //隐藏搜索结果
                        this.isShowSearchList = true;
                    },
                    fail: (info)=> {
                        //失败回调
                        console.log("查询关键字", info)
                    }
                })
            },
            getCurrentSingleLocation(data){
                let coordinate = data.location.split(',');
                this.markers = [
                    {
                        id:1,
                        longitude: coordinate[0],
                        latitude: coordinate[1],
                        iconPath:'../../static/img/mark_bs.png',
                        width:35,
                        height:50
                    }
                ]
                /* 更新地图中心点位 start */
                this.latitude = coordinate[1];
                this.longitude = coordinate[0];
                /* 更新地图中心点位 end */
                this.searchValue = data.name
                this.amapPlugin.getRegeo({
                    iconPathSelected: '../../static/img/mark_bs.png', //如:..­/..­/img/marker_checked.png
                    location:data.location,
                    success: (data) => {
                        //console.log(data)
                        //this.addressName = data[0].name;  
                        this.addressMap = data[0].regeocodeData.formatted_address;
                        this.regeocodeData = data[0].regeocodeData;
                        this.isShowSearchList = false;
                    },
                    fail: (info)=> {
                        //失败回调
                        console.log("getRegeo", info)
                    }
                });
            },
            //根据具体搜索结果查询
            searchCurrentLocation(data){
                this.amapPlugin.getInputtips({
                    key: this.key,
                    keywords: this.searchValue,
                    location: this.longitude + ',' + this.latitude,
                    success: (data) => {
                        //console.log(data);
                        let tempList = data.tips;
                        if(tempList.length >0){
                            for(let i in tempList){
                                if(tempList[i].name === this.searchValue){
                                    this.getCurrentSingleLocation(tempList[i]);
                                    break;
                                }
                            }
                        }
                        //隐藏搜索结果
                        this.isShowSearchList = false;
                    },
                    fail: (info)=> {
                        //失败回调
                        console.log("查询关键字", info)
                    }
                })
            },
            submit() {
                if (!this.addressMap) {
                    return;
                }
                if(JSON.stringify(this.regeocodeData) != '{}'){
                    let area = this.regeocodeData.addressComponent.district;
                    let areaCode = this.regeocodeData.addressComponent.adcode;
                    let township = this.regeocodeData.addressComponent.township;
                        this.$emit("update:address", this.addressMap);
                        this.$emit(
                            "update:areaAndStree",
                            area + township + this.addressMap
                        );
                        this.$emit("update:area", areaCode);
                        this.$emit("update:reportStreet", (typeof township == 'string') ? township : '');
                        this.show_ = false;
                        this.$emit("confirm");
                    }
                }
                
            }
}

<style lang="scss" scoped>
    ul,ul li{
        list-style: none;
    }
    .map_container {
        position: absolute;
        top: 0;
        bottom: 80px;
        left: 0;
        right: 0;
    }

    .map {
        width: 100%;
        height: 100%;
    }

    .map_text {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0px;
        height: 80px;
        background: #fff;
        padding: 0 15px;
    }
    .el-vue-search-box-container{
        position: fixed;
        background: #fff;
        box-shadow: 0 2px 2px raba(0,0,0,.15);
        border-radius: 2px 3px 3px 2px;
        z-index: 10;
        top: 0;
        left: 0;
        z-index: 10;
        background-color: #fff;
        width: 80%;
        .search-tips{
            position: absolute;
            top: 100%;
            border: 1px solid #dbdbdb;
            background: #fff;
            overflow: auto;
            max-width: 80%;
            >ul{
                >li{
                    height: 40px;
                    line-height: 40px;
                    box-shadow: 0 1px 1px rgba(0,0,0,.1);
                    padding: 0 10px;
                    cursor: pointer;
                }
            }
        }
        .section-search{
            display: flex;
            align-items: center;
            padding:0 20rpx;
            flex-direction: row;
            justify-content: space-between;
            height: 80rpx;
            line-height: 80rpx;
        }
    }
    
</style>

有关uni-app 微信小程序调用高德地图的更多相关文章

  1. ruby - RuntimeError(自动加载常量 Apps 多线程时检测到循环依赖 - 2

    我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("

  2. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

  3. ruby-on-rails - 每次我尝试部署时,我都会得到 - (gcloud.preview.app.deploy) 错误响应 : [4] DEADLINE_EXCEEDED - 2

    我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie

  4. c# - 如何在 ruby​​ 中调用 C# dll? - 2

    如何在ruby​​中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL

  5. ruby-on-rails - 如何重命名或移动 Rails 的 README_FOR_APP - 2

    当我在我的Rails应用程序根目录中运行rakedoc:app时,API文档是使用/doc/README_FOR_APP作为主页生成的。我想向该文件添加.rdoc扩展名,以便它在GitHub上正确呈现。更好的是,我想将它移动到应用程序根目录(/README.rdoc)。有没有办法通过修改包含的rake/rdoctask任务在我的Rakefile中执行此操作?是否有某个地方可以查找可以修改的主页文件的名称?还是我必须编写一个新的Rake任务?额外的问题:Rails应用程序的两个单独文件/README和/doc/README_FOR_APP背后的逻辑是什么?为什么不只有一个?

  6. java - 从 JRuby 调用 Java 类的问题 - 2

    我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www

  7. ruby - 调用其他方法的 TDD 方法的正确方法 - 2

    我需要一些关于TDD概念的帮助。假设我有以下代码defexecute(command)casecommandwhen"c"create_new_characterwhen"i"display_inventoryendenddefcreate_new_character#dostufftocreatenewcharacterenddefdisplay_inventory#dostufftodisplayinventoryend现在我不确定要为什么编写单元测试。如果我为execute方法编写单元测试,那不是几乎涵盖了我对create_new_character和display_invent

  8. 【鸿蒙应用开发系列】- 获取系统设备信息以及版本API兼容调用方式 - 2

    在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList​()Obt

  9. C51单片机——实现用独立按键控制LED亮灭(调用函数篇) - 2

    说在前面这部分我本来是合为一篇来写的,因为目的是一样的,都是通过独立按键来控制LED闪灭本质上是起到开关的作用,即调用函数和中断函数。但是写一篇太累了,我还是决定分为两篇写,这篇是调用函数篇。在本篇中你主要看到这些东西!!!1.调用函数的方法(主要讲语法和格式)2.独立按键如何控制LED亮灭3.程序中的一些细节(软件消抖等)1.调用函数的方法思路还是比较清晰地,就是通过按下按键来控制LED闪灭,即每按下一次,LED取反一次。重要的是,把按键与LED联系在一起。我打算用K1来作为开关,看了一下开发板原理图,K1连接的是单片机的P31口,当按下K1时,P31是与GND相连的,也就是说,当我按下去时

  10. ruby - 使用 postgres.app 在 rvm 下要求 pg 时出错 - 2

    我正在使用Postgres.app在OSX(10.8.3)上。我已经修改了我的PATH,以便应用程序的bin文件夹位于所有其他文件夹之前。Rammy:~phrogz$whichpg_config/Applications/Postgres.app/Contents/MacOS/bin/pg_config我已经安装了rvm并且可以毫无错误地安装pggem,但是当我需要它时我得到一个错误:Rammy:~phrogz$gem-v1.8.25Rammy:~phrogz$geminstallpgFetching:pg-0.15.1.gem(100%)Buildingnativeextension

随机推荐