使用andorid studio获取经纬度信息

可以使用模拟器或者安卓真机_建议真机_

小节简介

平台:andorid studio3.5.2
涉及文件:acticity_main.xml、AndoridManifest.xml、MainActivity.java

原理介绍

activity_main.xml文件
代码如下
注意,GPS定位必须在室外进行测试,室内测试获得数据比较困难

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
//以上代码无需粘贴,只需粘贴一个TextView组件即可

    <TextView
        android:id="@+id/location"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:textSize="30sp"/>

//此行无需粘贴,自己会生成
</androidx.constraintlayout.widget.ConstraintLayout>

代码语句解释

  1. android:layout_width/height 这个是用来控制组件的宽度和高度的,你看他英文就这么写的了对不对,其中match_parent是填满父容器,wrap_content是组件实际大小。
  2. id是为组件设计一个资源id,可以
  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值