Kotlin应用程序中的“地理位置”按钮不可用

马里耶斯

我正在尝试创建一个可以获取您的位置并同时保存标记的地图应用程序。

但我在尝试添加FloatingButton同一时间时遇到了麻烦

这是我content_main.XMLLoactionButton和以前IS的.XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.google.android.material.appbar.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary">
                <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_weight="13"
                    android:orientation="horizontal"
                    android:gravity="center_vertical">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/app_name"
                        android:textColor="#FFFFFF"
                        style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"/>
                </RelativeLayout>
            </androidx.appcompat.widget.Toolbar>
    </com.google.android.material.appbar.AppBarLayout>
</LinearLayout>

我已经更换LinearLayout与元素RelativeLayout,因为试图将一个FloatingButtoncontent_main.xml我取得下一个.xml先前的图像是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.google.android.material.appbar.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary">
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="13"
                android:orientation="horizontal"
                android:gravity="center_vertical">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/app_name"
                    android:textColor="#FFFFFF"
                    style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"/>
            </LinearLayout>
        </androidx.appcompat.widget.Toolbar>
    </com.google.android.material.appbar.AppBarLayout>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        android:layout_marginTop="180dp"
        android:backgroundTint="#FFF"
        android:clickable="true"
        android:focusable="true"
        app:fabSize="normal">
    </com.google.android.material.floatingactionbutton.FloatingActionButton>

</LinearLayout>

因此,在google中搜索了许多示例,我发现有人使用RelativeLayout来放置FloatingButton主要内容。我决定更改为put RelativeLayout,但是LocationButton这样无法使用,以前的.xml是下一个,并且是实际的:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.google.android.material.appbar.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary">
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_weight="13"
                android:orientation="horizontal"
                android:gravity="center_vertical">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/app_name"
                    android:textColor="#FFFFFF"
                    style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"/>
            </LinearLayout>
        </androidx.appcompat.widget.Toolbar>
    </com.google.android.material.appbar.AppBarLayout>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        android:layout_marginTop="180dp"
        android:backgroundTint="#FFF"
        android:clickable="true"
        android:focusable="true"
        app:fabSize="normal">
    </com.google.android.material.floatingactionbutton.FloatingActionButton>

</RelativeLayout>

我搜索了很多示例,并修改了我的示例,content_main.xml但是我没有解决方案将位置按钮与FloatingButton一起放置。

怎样才能加上FloatingButton我的实际LocationButton

编辑:这是我的ButtonLocation

 override fun onMapReady(googleMap: GoogleMap) {
        mMap = googleMap //Princiapal Map Variable
        mMap.setOnMarkerClickListener(this) //Location Marker
        mMap.uiSettings.isZoomControlsEnabled = true //Zoom in maps enabled
        mMap.uiSettings.isMyLocationButtonEnabled = true

        setUpMap() //Function to detect actual location
    }

编辑图像:

这是我使用.xml的实际布局模型但是现在我遇到了问题Toolbar Widget

lurker0152

你已经有东西了。红色的浮动按钮位于地图顶部,这是您想要的。要查看Google的位置按钮(通常在右上角),您需要发出以下命令:

mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(true);

编辑:对于Kotlin,请使用以下代码段:

override fun onMapReady(googleMap: GoogleMap) {
  mMap = googleMap

  this.setUpMap()
}

companion object {
  private const val LOCATION_PERMISSION_REQUEST_CODE = 1
}

private fun setUpMap() {

  if (ActivityCompat.checkSelfPermission(this,
      android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this,
      arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION), LOCATION_PERMISSION_REQUEST_CODE)
    return
  }

  mMap.isMyLocationEnabled = true
}

override fun onRequestPermissionsResult(requestCode: Int,
                                        permissions: Array<String>, grantResults: IntArray) {
  when (requestCode) {
    LOCATION_PERMISSION_REQUEST_CODE -> {
      // If request is cancelled, the result arrays are empty.
      if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
        // permission was granted, yay! Do the task you need to do.
        setUpMap()
      } else {
        // permission denied, boo!
      }
      return
    }
    else -> {
      // Ignore all other requests.
    }
  }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如果地理位置不可用,请禁用按钮

来自分类Dev

解析用于地理位置iOS应用程序的json

来自分类Dev

地理位置给timeout错误Cordova Android应用程序

来自分类Dev

如何在桌面应用程序中获取当前地理位置?

来自分类Dev

运行应用程序时出错:“项目不可用”

来自分类Dev

请求之间的应用程序类变量不可用

来自分类Dev

RESTfull Jersey应用程序,请求的资源不可用

来自分类Dev

C# 应用程序默认凭据不可用

来自分类Dev

导出路由器中的路由在应用程序中不可用

来自分类Dev

从Windows控制台应用程序退出代码在git hook脚本中不可用

来自分类Dev

XCode11错误“在应用程序扩展中,open(_:options:completionHandler :)不可用”

来自分类Dev

Grails插件依赖项在应用程序中不可用

来自分类Dev

zlib在cx冻结的python 3.4应用程序中不可用

来自分类Dev

地理位置确认框,显示我在phonegap ios应用程序中的索引文件url

来自分类Dev

如何在Windows Phone 8.1通用应用程序中获取街道地址的地理位置?

来自分类Dev

使用应用程序中嵌入的浏览器时,无法从Android上的网页访问地理位置

来自分类Dev

如何在Windows Phone 8.1通用应用程序中获取街道地址的地理位置?

来自分类Dev

ENV变量仅在生产控制台中可用,而在应用程序中不可用-Rails,Figaro Gem

来自分类Dev

ENV变量仅在生产控制台中可用,而在应用程序中不可用-Rails,Figaro Gem

来自分类Dev

即使选项卡不清晰,仍从Web应用程序发送地理位置信息?

来自分类Dev

非https上的地理位置仍然可以在Ionic应用程序上使用吗?

来自分类Dev

飞行模式下的Rubymotion / bubblewrap地理位置使应用程序崩溃

来自分类Dev

如何在React应用程序中this.refs不可用的函数中访问DOM元素?

来自分类Dev

将 PHP 应用程序迁移到 Laravel。Laravel 中的 $_SESSION 数据集在旧的应用程序 php 文件中不可用

来自分类Dev

如何在不使用Google Map Direction API的情况下在Android应用程序中查找2个地理位置之间的距离(按公路)?

来自分类Dev

即使应用程序未在Cordova中运行,如何每隔5分钟获取一次地理位置信息

来自分类常见问题

http错误503服务不可用。应用程序池在访问网站时停止

来自分类Dev

为什么Google Play商店未显示应用程序设备不可用的原因?

来自分类Dev

在Windows 8应用程序中共享图像时,为什么“邮件”选项不可用?

Related 相关文章

  1. 1

    如果地理位置不可用,请禁用按钮

  2. 2

    解析用于地理位置iOS应用程序的json

  3. 3

    地理位置给timeout错误Cordova Android应用程序

  4. 4

    如何在桌面应用程序中获取当前地理位置?

  5. 5

    运行应用程序时出错:“项目不可用”

  6. 6

    请求之间的应用程序类变量不可用

  7. 7

    RESTfull Jersey应用程序,请求的资源不可用

  8. 8

    C# 应用程序默认凭据不可用

  9. 9

    导出路由器中的路由在应用程序中不可用

  10. 10

    从Windows控制台应用程序退出代码在git hook脚本中不可用

  11. 11

    XCode11错误“在应用程序扩展中,open(_:options:completionHandler :)不可用”

  12. 12

    Grails插件依赖项在应用程序中不可用

  13. 13

    zlib在cx冻结的python 3.4应用程序中不可用

  14. 14

    地理位置确认框,显示我在phonegap ios应用程序中的索引文件url

  15. 15

    如何在Windows Phone 8.1通用应用程序中获取街道地址的地理位置?

  16. 16

    使用应用程序中嵌入的浏览器时,无法从Android上的网页访问地理位置

  17. 17

    如何在Windows Phone 8.1通用应用程序中获取街道地址的地理位置?

  18. 18

    ENV变量仅在生产控制台中可用,而在应用程序中不可用-Rails,Figaro Gem

  19. 19

    ENV变量仅在生产控制台中可用,而在应用程序中不可用-Rails,Figaro Gem

  20. 20

    即使选项卡不清晰,仍从Web应用程序发送地理位置信息?

  21. 21

    非https上的地理位置仍然可以在Ionic应用程序上使用吗?

  22. 22

    飞行模式下的Rubymotion / bubblewrap地理位置使应用程序崩溃

  23. 23

    如何在React应用程序中this.refs不可用的函数中访问DOM元素?

  24. 24

    将 PHP 应用程序迁移到 Laravel。Laravel 中的 $_SESSION 数据集在旧的应用程序 php 文件中不可用

  25. 25

    如何在不使用Google Map Direction API的情况下在Android应用程序中查找2个地理位置之间的距离(按公路)?

  26. 26

    即使应用程序未在Cordova中运行,如何每隔5分钟获取一次地理位置信息

  27. 27

    http错误503服务不可用。应用程序池在访问网站时停止

  28. 28

    为什么Google Play商店未显示应用程序设备不可用的原因?

  29. 29

    在Windows 8应用程序中共享图像时,为什么“邮件”选项不可用?

热门标签

归档