android - 使用 Google 地图显示特定地点,但使用代码
问题描述
我正在使用 kotlin 开发一个应用程序,在其中我实现了谷歌地图及其 API,或者我获得了位置和所有内容,但我需要的是过滤特定类型的地点,它将在应用程序中预定义,并且它的工作原理当进行搜索时,例如使用医院,并显示附近的医院,您将如何从代码中进行此搜索?
class HomeActivity : AppCompatActivity(), OnMapReadyCallback, GoogleMap.OnMarkerClickListener {
private lateinit var fusedLocationClient : FusedLocationProviderClient
private lateinit var lastLocation: Location
companion object {
private const val LOCATION_PERMISSION_REQUEST_CODE = 1
}
private lateinit var map: GoogleMap
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
val mapFragment = supportFragmentManager
.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this)
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this)
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
override fun onMapReady(googleMap: GoogleMap) {
map = googleMap
map.setOnMarkerClickListener(this)
map.uiSettings.isZoomControlsEnabled = true
setUpMap()
}
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
}
map.isMyLocationEnabled = true
map.mapType = GoogleMap.MAP_TYPE_HYBRID
fusedLocationClient.lastLocation.addOnSuccessListener (this){location:Location ->
lastLocation = location
val currentLatLong = LatLng(location.latitude, location.longitude)
map.animateCamera(CameraUpdateFactory.newLatLngZoom(currentLatLong, 16f))
}
}
override fun onMarkerClick(p0: Marker?): Boolean = false
这是我目前拥有的代码,它是控制地图上所有内容的代码
我要求你给我看这样的网站。
解决方案
推荐阅读
- swift4 - 哪个最好为 UIButton 提供 shadowColor、Radius、Opacity 和cornerRadius?按钮扩展或 IBDesignable?
- ms-access - MS Access - 在表单之间传递登录信息
- c# - 如何在 Windows 窗体应用程序 C# 中检索 Google 联系人?
- database - 如何每天存储和索引数十亿条日志
- amazon-web-services - Kinesis Firehose 数据传输延迟
- gradle - Doop:Gradle 构建失败并出现异常。无法解决依赖关系
- c# - C# SQL Server 存储过程参数返回列表
- c# - SafeArray 无法封送为此数组类型,因为它具有非零下限或多于一维
- firebase - 如何找到属于 Firebase 应用程序的用户?
- typescript - 打字稿中的 Getter/Setter