mirror of
https://github.com/googlemaps/android-samples.git
synced 2025-12-08 18:02:20 +00:00
feat: Add missing Kotlin samples (#428)
* Gradle bump and rename CloseInfoWindowDemoActivity * Adding CameraClampingDemoActivity. * Fix build error. * Add location source.
This commit is contained in:
parent
ab6e0e8d32
commit
e6cf1b0202
@ -67,7 +67,9 @@ dependencies {
|
||||
implementation 'androidx.multidex:multidex:2.0.1'
|
||||
|
||||
// GMS
|
||||
gmsImplementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0'
|
||||
gmsImplementation 'com.google.android.gms:play-services-maps:17.0.0'
|
||||
gmsImplementation 'com.google.maps.android:maps-ktx:2.2.0'
|
||||
|
||||
// V3
|
||||
v3Implementation 'com.google.android.libraries.maps:maps:3.1.0-beta'
|
||||
|
||||
@ -16,47 +16,49 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.kotlindemos">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".BasicMapDemoActivity" />
|
||||
<activity android:name=".CameraDemoActivity"/>
|
||||
<activity android:name=".CircleDemoActivity" />
|
||||
<activity android:name=".CloseInfoWindowDemoActivity" />
|
||||
<activity android:name=".EventsDemoActivity" />
|
||||
<activity android:name=".GroundOverlayDemoActivity" />
|
||||
<activity android:name=".IndoorDemoActivity" />
|
||||
<activity android:name=".LayersDemoActivity"/>
|
||||
<activity android:name=".LiteDemoActivity" />
|
||||
<activity android:name=".LiteListDemoActivity" />
|
||||
<activity android:name=".MarkerDemoActivity"/>
|
||||
<activity android:name=".MyLocationDemoActivity" />
|
||||
<activity android:name=".PolygonDemoActivity"/>
|
||||
<activity android:name=".SplitStreetViewPanoramaAndMapDemoActivity" />
|
||||
<activity android:name=".StreetViewPanoramaBasicDemoActivity" />
|
||||
<activity android:name=".StreetViewPanoramaEventsDemoActivity" />
|
||||
<activity android:name=".StreetViewPanoramaNavigationDemoActivity" />
|
||||
<activity android:name=".StreetViewPanoramaOptionsDemoActivity" />
|
||||
<activity android:name=".StreetViewPanoramaViewDemoActivity" />
|
||||
<activity android:name=".TagsDemoActivity"/>
|
||||
<activity android:name=".TileCoordinateDemoActivity"/>
|
||||
<activity android:name=".TileOverlayDemoActivity"/>
|
||||
<activity android:name=".UiSettingsDemoActivity" />
|
||||
<activity android:name=".VisibleRegionDemoActivity"/>
|
||||
<activity android:name=".polyline.PolylineDemoActivity" />
|
||||
<activity android:name=".RawMapViewDemoActivity" />
|
||||
</application>
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".BasicMapDemoActivity" />
|
||||
<activity android:name=".CameraDemoActivity" />
|
||||
<activity android:name=".CameraClampingDemoActivity" />
|
||||
<activity android:name=".CircleDemoActivity" />
|
||||
<activity android:name=".MarkerCloseInfoWindowOnRetapDemoActivity" />
|
||||
<activity android:name=".EventsDemoActivity" />
|
||||
<activity android:name=".GroundOverlayDemoActivity" />
|
||||
<activity android:name=".IndoorDemoActivity" />
|
||||
<activity android:name=".LayersDemoActivity" />
|
||||
<activity android:name=".LiteDemoActivity" />
|
||||
<activity android:name=".LiteListDemoActivity" />
|
||||
<activity android:name=".LocationSourceDemoActivity" />
|
||||
<activity android:name=".MarkerDemoActivity" />
|
||||
<activity android:name=".MyLocationDemoActivity" />
|
||||
<activity android:name=".PolygonDemoActivity" />
|
||||
<activity android:name=".SplitStreetViewPanoramaAndMapDemoActivity" />
|
||||
<activity android:name=".StreetViewPanoramaBasicDemoActivity" />
|
||||
<activity android:name=".StreetViewPanoramaEventsDemoActivity" />
|
||||
<activity android:name=".StreetViewPanoramaNavigationDemoActivity" />
|
||||
<activity android:name=".StreetViewPanoramaOptionsDemoActivity" />
|
||||
<activity android:name=".StreetViewPanoramaViewDemoActivity" />
|
||||
<activity android:name=".TagsDemoActivity" />
|
||||
<activity android:name=".TileCoordinateDemoActivity" />
|
||||
<activity android:name=".TileOverlayDemoActivity" />
|
||||
<activity android:name=".UiSettingsDemoActivity" />
|
||||
<activity android:name=".VisibleRegionDemoActivity" />
|
||||
<activity android:name=".polyline.PolylineDemoActivity" />
|
||||
<activity android:name=".RawMapViewDemoActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@ -0,0 +1,145 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
package com.example.kotlindemos
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.gms.maps.CameraUpdateFactory
|
||||
import com.google.android.gms.maps.GoogleMap
|
||||
import com.google.android.gms.maps.GoogleMap.OnCameraIdleListener
|
||||
import com.google.android.gms.maps.OnMapReadyCallback
|
||||
import com.google.android.gms.maps.SupportMapFragment
|
||||
import com.google.android.gms.maps.model.CameraPosition
|
||||
import com.google.android.gms.maps.model.LatLng
|
||||
import com.google.android.gms.maps.model.LatLngBounds
|
||||
import com.google.maps.android.ktx.CameraIdleEvent
|
||||
import com.google.maps.android.ktx.awaitMap
|
||||
import com.google.maps.android.ktx.cameraEvents
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* This shows how to constrain the camera to specific boundaries and zoom levels.
|
||||
*/
|
||||
class CameraClampingDemoActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var map: GoogleMap
|
||||
private lateinit var cameraTextView: TextView
|
||||
private val buttonIdToLatLngBoundsCameraMap = mapOf(
|
||||
Pair(R.id.clamp_latlng_adelaide, Pair(ADELAIDE, ADELAIDE_CAMERA)),
|
||||
Pair(R.id.clamp_latlng_pacific, Pair(PACIFIC, PACIFIC_CAMERA)),
|
||||
)
|
||||
|
||||
/**
|
||||
* Internal min zoom level that can be toggled via the demo.
|
||||
*/
|
||||
private var minZoom = DEFAULT_MIN_ZOOM
|
||||
|
||||
/**
|
||||
* Internal max zoom level that can be toggled via the demo.
|
||||
*/
|
||||
private var maxZoom = DEFAULT_MAX_ZOOM
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.camera_clamping_demo)
|
||||
cameraTextView = findViewById(R.id.camera_text)
|
||||
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
|
||||
lifecycleScope.launchWhenCreated {
|
||||
map = mapFragment.awaitMap()
|
||||
launch {
|
||||
map.cameraEvents().collect { event ->
|
||||
when (event) {
|
||||
is CameraIdleEvent -> onCameraIdle()
|
||||
else -> Log.d(TAG, "Got event: $event")
|
||||
}
|
||||
}
|
||||
}
|
||||
setButtonClickListeners()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setButtonClickListeners() {
|
||||
// Min/max zooms
|
||||
findViewById<Button>(R.id.clamp_min_zoom).setOnClickListener {
|
||||
minZoom += ZOOM_DELTA
|
||||
// Constrains the minimum zoom level.
|
||||
map.setMinZoomPreference(minZoom)
|
||||
toast("Min zoom preference set to: $minZoom")
|
||||
}
|
||||
findViewById<Button>(R.id.clamp_max_zoom).setOnClickListener {
|
||||
maxZoom -= ZOOM_DELTA
|
||||
// Constrains the maximum zoom level.
|
||||
map.setMaxZoomPreference(maxZoom)
|
||||
toast("Max zoom preference set to: $maxZoom")
|
||||
}
|
||||
findViewById<Button>(R.id.clamp_zoom_reset).setOnClickListener {
|
||||
resetMinMaxZoom()
|
||||
map.resetMinMaxZoomPreference()
|
||||
toast("Min/Max zoom preferences reset.")
|
||||
}
|
||||
|
||||
// Clamp
|
||||
val clampListener: (View) -> Unit = { view ->
|
||||
buttonIdToLatLngBoundsCameraMap[view.id]?.let { (latLngBounds, camera) ->
|
||||
map.setLatLngBoundsForCameraTarget(latLngBounds)
|
||||
map.animateCamera(CameraUpdateFactory.newCameraPosition(camera))
|
||||
}
|
||||
}
|
||||
findViewById<Button>(R.id.clamp_latlng_adelaide).setOnClickListener(clampListener)
|
||||
findViewById<Button>(R.id.clamp_latlng_pacific).setOnClickListener(clampListener)
|
||||
findViewById<Button>(R.id.clamp_latlng_reset).setOnClickListener {
|
||||
map.setLatLngBoundsForCameraTarget(null)
|
||||
toast("LatLngBounds clamp reset.")
|
||||
}
|
||||
}
|
||||
|
||||
private fun onCameraIdle() {
|
||||
cameraTextView.text = map.cameraPosition.toString()
|
||||
}
|
||||
|
||||
|
||||
private fun toast(msg: String) {
|
||||
Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
private fun resetMinMaxZoom() {
|
||||
minZoom = DEFAULT_MIN_ZOOM
|
||||
maxZoom = DEFAULT_MAX_ZOOM
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = CameraClampingDemoActivity::class.java.name
|
||||
private const val ZOOM_DELTA = 2.0f
|
||||
private const val DEFAULT_MIN_ZOOM = 2.0f
|
||||
private const val DEFAULT_MAX_ZOOM = 22.0f
|
||||
private val ADELAIDE = LatLngBounds(
|
||||
LatLng(-35.0, 138.58), LatLng(-34.9, 138.61))
|
||||
private val ADELAIDE_CAMERA = CameraPosition.Builder()
|
||||
.target(LatLng(-34.92873, 138.59995)).zoom(20.0f).bearing(0f).tilt(0f).build()
|
||||
private val PACIFIC = LatLngBounds(
|
||||
LatLng(-15.0, 165.0), LatLng(15.0, -165.0))
|
||||
private val PACIFIC_CAMERA = CameraPosition.Builder()
|
||||
.target(LatLng(0.0, (-180).toDouble())).zoom(4.0f).bearing(0f).tilt(0f).build()
|
||||
}
|
||||
}
|
||||
@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright 2018 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.kotlindemos
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.example.kotlindemos.OnMapAndViewReadyListener.OnGlobalLayoutAndMapReadyListener
|
||||
import com.google.android.gms.maps.CameraUpdateFactory
|
||||
import com.google.android.gms.maps.GoogleMap
|
||||
import com.google.android.gms.maps.SupportMapFragment
|
||||
import com.google.android.gms.maps.model.LatLng
|
||||
import com.google.android.gms.maps.model.LatLngBounds
|
||||
import com.google.android.gms.maps.model.Marker
|
||||
import com.google.android.gms.maps.model.MarkerOptions
|
||||
|
||||
|
||||
/**
|
||||
* This shows how to close the info window when the currently selected marker is re-tapped.
|
||||
*/
|
||||
class CloseInfoWindowDemoActivity :
|
||||
AppCompatActivity(),
|
||||
OnGlobalLayoutAndMapReadyListener {
|
||||
|
||||
private lateinit var map: GoogleMap
|
||||
|
||||
/** Keeps track of the selected marker. It will be set to null if no marker is selected. */
|
||||
private var selectedMarker: Marker? = null
|
||||
|
||||
/**
|
||||
* If user tapped on the the marker which was already showing info window,
|
||||
* the showing info window will be closed. Otherwise will show a different window.
|
||||
*/
|
||||
private val markerClickListener = object : GoogleMap.OnMarkerClickListener {
|
||||
override fun onMarkerClick(marker: Marker?): Boolean {
|
||||
if (marker == selectedMarker) {
|
||||
selectedMarker = null
|
||||
// Return true to indicate we have consumed the event and that we do not
|
||||
// want the the default behavior to occur (which is for the camera to move
|
||||
// such that the marker is centered and for the marker's info window to open,
|
||||
// if it has one).
|
||||
return true
|
||||
}
|
||||
|
||||
selectedMarker = marker
|
||||
// Return false to indicate that we have not consumed the event and that
|
||||
// we wish for the default behavior to occur.
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_marker_close_info_window_on_retap_demo)
|
||||
|
||||
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
|
||||
OnMapAndViewReadyListener(mapFragment, this)
|
||||
}
|
||||
|
||||
override fun onMapReady(googleMap: GoogleMap?) {
|
||||
// Return if googleMap was null
|
||||
map = googleMap ?: return
|
||||
|
||||
with(map) {
|
||||
uiSettings.isZoomControlsEnabled = false
|
||||
|
||||
setOnMarkerClickListener(markerClickListener)
|
||||
|
||||
// Set listener for map click event. Any showing info window closes
|
||||
// when the map is clicked. Clear the currently selected marker.
|
||||
setOnMapClickListener { selectedMarker = null }
|
||||
|
||||
setContentDescription(getString(R.string.close_info_window_demo_details))
|
||||
|
||||
// Add markers to different cities in Australia and include it in bounds
|
||||
val bounds = LatLngBounds.Builder()
|
||||
cities.map { city ->
|
||||
addMarker(MarkerOptions().apply {
|
||||
position(city.latLng)
|
||||
title(city.title)
|
||||
snippet(city.snippet)
|
||||
})
|
||||
bounds.include(city.latLng)
|
||||
}
|
||||
|
||||
moveCamera(CameraUpdateFactory.newLatLngBounds(bounds.build(), 50))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to contain information about a marker.
|
||||
*
|
||||
* @property latLng latitude and longitude of the marker
|
||||
* @property title a string containing the city name
|
||||
* @property snippet a string containing the population of the city
|
||||
*/
|
||||
class MarkerInfo(val latLng: LatLng, val title: String, val snippet: String)
|
||||
|
||||
private val cities = listOf(
|
||||
MarkerInfo(LatLng(-27.47093, 153.0235),
|
||||
"Brisbane", "Population: 2,074,200"),
|
||||
MarkerInfo(LatLng(-37.81319, 144.96298),
|
||||
"Melbourne", "Population: 4,137,400"),
|
||||
MarkerInfo(LatLng(-33.87365, 151.20689),
|
||||
"Sydney", "Population: 4,627,300"),
|
||||
MarkerInfo(LatLng(-34.92873, 138.59995),
|
||||
"Adelaide", "Population: 1,213,000"),
|
||||
MarkerInfo(LatLng(-31.952854, 115.857342),
|
||||
"Perth", "Population: 1,738,800")
|
||||
)
|
||||
}
|
||||
@ -22,86 +22,91 @@ import com.example.kotlindemos.polyline.PolylineDemoActivity
|
||||
* A list of all the demos we have available.
|
||||
*/
|
||||
class DemoDetailsList {
|
||||
companion object {
|
||||
val DEMOS = listOf<DemoDetails>(
|
||||
DemoDetails(R.string.basic_demo_label, R.string.basic_demo_details,
|
||||
BasicMapDemoActivity::class.java),
|
||||
DemoDetails(R.string.camera_demo_label, R.string.camera_demo_description,
|
||||
CameraDemoActivity::class.java),
|
||||
DemoDetails(R.string.circle_demo_label, R.string.circle_demo_details,
|
||||
CircleDemoActivity::class.java),
|
||||
DemoDetails(R.string.close_info_window_demo_label,
|
||||
R.string.close_info_window_demo_details,
|
||||
CloseInfoWindowDemoActivity::class.java),
|
||||
DemoDetails(
|
||||
R.string.events_demo_label,
|
||||
R.string.events_demo_details,
|
||||
EventsDemoActivity::class.java),
|
||||
DemoDetails(
|
||||
R.string.ground_overlay_demo_label,
|
||||
R.string.ground_overlay_demo_details,
|
||||
GroundOverlayDemoActivity::class.java),
|
||||
DemoDetails(R.string.indoor_demo_label, R.string.indoor_demo_details,
|
||||
IndoorDemoActivity::class.java),
|
||||
DemoDetails(R.string.layers_demo_label, R.string.layers_demo_description,
|
||||
LayersDemoActivity::class.java),
|
||||
DemoDetails(R.string.lite_demo_label, R.string.lite_demo_details,
|
||||
LiteDemoActivity::class.java),
|
||||
DemoDetails(R.string.lite_list_demo_label, R.string.lite_list_demo_details,
|
||||
LiteListDemoActivity::class.java),
|
||||
DemoDetails(R.string.markers_demo_label, R.string.markers_demo_description,
|
||||
MarkerDemoActivity::class.java),
|
||||
DemoDetails(R.string.my_location_demo_label, R.string.my_location_demo_details,
|
||||
MyLocationDemoActivity::class.java),
|
||||
DemoDetails(R.string.polygon_demo_label, R.string.polygon_demo_details,
|
||||
PolygonDemoActivity::class.java),
|
||||
DemoDetails(R.string.polyline_demo_label, R.string.polyline_demo_description,
|
||||
PolylineDemoActivity::class.java),
|
||||
DemoDetails(
|
||||
R.string.raw_map_view_demo_label,
|
||||
R.string.raw_map_view_demo_description,
|
||||
RawMapViewDemoActivity::class.java),
|
||||
DemoDetails(
|
||||
R.string.street_view_panorama_basic_demo_label,
|
||||
R.string.street_view_panorama_basic_demo_details,
|
||||
StreetViewPanoramaBasicDemoActivity::class.java),
|
||||
DemoDetails(
|
||||
R.string.street_view_panorama_navigation_demo_label,
|
||||
R.string.street_view_panorama_navigation_demo_details,
|
||||
StreetViewPanoramaNavigationDemoActivity::class.java),
|
||||
DemoDetails(
|
||||
R.string.split_street_view_panorama_and_map_demo_label,
|
||||
R.string.split_street_view_panorama_and_map_demo_details,
|
||||
SplitStreetViewPanoramaAndMapDemoActivity::class.java),
|
||||
DemoDetails(
|
||||
R.string.street_view_panorama_options_demo_label,
|
||||
R.string.street_view_panorama_options_demo_details,
|
||||
StreetViewPanoramaOptionsDemoActivity::class.java),
|
||||
DemoDetails(
|
||||
R.string.street_view_panorama_events_demo_label,
|
||||
R.string.street_view_panorama_events_demo_details,
|
||||
StreetViewPanoramaEventsDemoActivity::class.java),
|
||||
DemoDetails(
|
||||
R.string.street_view_panorama_view_demo_label,
|
||||
R.string.street_view_panorama_view_demo_details,
|
||||
StreetViewPanoramaViewDemoActivity::class.java
|
||||
),
|
||||
DemoDetails(R.string.tags_demo_label, R.string.tags_demo_details,
|
||||
TagsDemoActivity::class.java),
|
||||
DemoDetails(
|
||||
R.string.tile_coordinate_demo_label,
|
||||
R.string.tile_coordinate_demo_description,
|
||||
TileCoordinateDemoActivity::class.java
|
||||
),
|
||||
DemoDetails(
|
||||
R.string.tile_overlay_demo_label,
|
||||
R.string.tile_overlay_demo_description,
|
||||
TileOverlayDemoActivity::class.java
|
||||
),
|
||||
DemoDetails(R.string.ui_settings_demo_label, R.string.ui_settings_demo_details,
|
||||
UiSettingsDemoActivity::class.java),
|
||||
DemoDetails(R.string.region_demo_label, R.string.region_demo_details,
|
||||
VisibleRegionDemoActivity::class.java)
|
||||
)
|
||||
}
|
||||
companion object {
|
||||
val DEMOS = listOf(
|
||||
DemoDetails(R.string.basic_demo_label,
|
||||
R.string.basic_demo_details,
|
||||
BasicMapDemoActivity::class.java),
|
||||
DemoDetails(R.string.camera_demo_label,
|
||||
R.string.camera_demo_description,
|
||||
CameraDemoActivity::class.java),
|
||||
DemoDetails(R.string.camera_clamping_demo_label,
|
||||
R.string.camera_clamping_demo_description,
|
||||
CameraClampingDemoActivity::class.java),
|
||||
DemoDetails(R.string.circle_demo_label, R.string.circle_demo_details,
|
||||
CircleDemoActivity::class.java),
|
||||
DemoDetails(R.string.close_info_window_demo_label,
|
||||
R.string.close_info_window_demo_details,
|
||||
MarkerCloseInfoWindowOnRetapDemoActivity::class.java),
|
||||
DemoDetails(R.string.events_demo_label,
|
||||
R.string.events_demo_details,
|
||||
EventsDemoActivity::class.java),
|
||||
DemoDetails(R.string.ground_overlay_demo_label,
|
||||
R.string.ground_overlay_demo_details,
|
||||
GroundOverlayDemoActivity::class.java),
|
||||
DemoDetails(R.string.indoor_demo_label,
|
||||
R.string.indoor_demo_details,
|
||||
IndoorDemoActivity::class.java),
|
||||
DemoDetails(R.string.layers_demo_label,
|
||||
R.string.layers_demo_description,
|
||||
LayersDemoActivity::class.java),
|
||||
DemoDetails(R.string.lite_demo_label,
|
||||
R.string.lite_demo_details,
|
||||
LiteDemoActivity::class.java),
|
||||
DemoDetails(R.string.location_source_demo_label,
|
||||
R.string.location_source_demo_description,
|
||||
LocationSourceDemoActivity::class.java),
|
||||
DemoDetails(R.string.lite_list_demo_label,
|
||||
R.string.lite_list_demo_details,
|
||||
LiteListDemoActivity::class.java),
|
||||
DemoDetails(R.string.markers_demo_label,
|
||||
R.string.markers_demo_description,
|
||||
MarkerDemoActivity::class.java),
|
||||
DemoDetails(R.string.my_location_demo_label,
|
||||
R.string.my_location_demo_details,
|
||||
MyLocationDemoActivity::class.java),
|
||||
DemoDetails(R.string.polygon_demo_label,
|
||||
R.string.polygon_demo_details,
|
||||
PolygonDemoActivity::class.java),
|
||||
DemoDetails(R.string.polyline_demo_label,
|
||||
R.string.polyline_demo_description,
|
||||
PolylineDemoActivity::class.java),
|
||||
DemoDetails(R.string.raw_map_view_demo_label,
|
||||
R.string.raw_map_view_demo_description,
|
||||
RawMapViewDemoActivity::class.java),
|
||||
DemoDetails(R.string.street_view_panorama_basic_demo_label,
|
||||
R.string.street_view_panorama_basic_demo_details,
|
||||
StreetViewPanoramaBasicDemoActivity::class.java),
|
||||
DemoDetails(R.string.street_view_panorama_navigation_demo_label,
|
||||
R.string.street_view_panorama_navigation_demo_details,
|
||||
StreetViewPanoramaNavigationDemoActivity::class.java),
|
||||
DemoDetails(R.string.split_street_view_panorama_and_map_demo_label,
|
||||
R.string.split_street_view_panorama_and_map_demo_details,
|
||||
SplitStreetViewPanoramaAndMapDemoActivity::class.java),
|
||||
DemoDetails(R.string.street_view_panorama_options_demo_label,
|
||||
R.string.street_view_panorama_options_demo_details,
|
||||
StreetViewPanoramaOptionsDemoActivity::class.java),
|
||||
DemoDetails(R.string.street_view_panorama_events_demo_label,
|
||||
R.string.street_view_panorama_events_demo_details,
|
||||
StreetViewPanoramaEventsDemoActivity::class.java),
|
||||
DemoDetails(R.string.street_view_panorama_view_demo_label,
|
||||
R.string.street_view_panorama_view_demo_details,
|
||||
StreetViewPanoramaViewDemoActivity::class.java),
|
||||
DemoDetails(R.string.tags_demo_label,
|
||||
R.string.tags_demo_details,
|
||||
TagsDemoActivity::class.java),
|
||||
DemoDetails(R.string.tile_coordinate_demo_label,
|
||||
R.string.tile_coordinate_demo_description,
|
||||
TileCoordinateDemoActivity::class.java),
|
||||
DemoDetails(R.string.tile_overlay_demo_label,
|
||||
R.string.tile_overlay_demo_description,
|
||||
TileOverlayDemoActivity::class.java),
|
||||
DemoDetails(R.string.ui_settings_demo_label,
|
||||
R.string.ui_settings_demo_details,
|
||||
UiSettingsDemoActivity::class.java),
|
||||
DemoDetails(R.string.region_demo_label,
|
||||
R.string.region_demo_details,
|
||||
VisibleRegionDemoActivity::class.java)
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,112 @@
|
||||
// Copyright 2020 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
package com.example.kotlindemos
|
||||
|
||||
import android.Manifest.permission
|
||||
import android.content.pm.PackageManager
|
||||
import android.location.Location
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.LifecycleObserver
|
||||
import androidx.lifecycle.OnLifecycleEvent
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.gms.maps.GoogleMap
|
||||
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener
|
||||
import com.google.android.gms.maps.LocationSource
|
||||
import com.google.android.gms.maps.LocationSource.OnLocationChangedListener
|
||||
import com.google.android.gms.maps.SupportMapFragment
|
||||
import com.google.android.gms.maps.model.LatLng
|
||||
import com.google.maps.android.ktx.awaitMap
|
||||
|
||||
/**
|
||||
* This shows how to use a custom location source.
|
||||
*/
|
||||
class LocationSourceDemoActivity : AppCompatActivity() {
|
||||
|
||||
private val locationSource = LongPressLocationSource()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_basic_map_demo)
|
||||
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val map = mapFragment.awaitMap()
|
||||
init(map = map)
|
||||
}
|
||||
lifecycle.addObserver(locationSource)
|
||||
}
|
||||
|
||||
private fun init(map: GoogleMap) {
|
||||
map.setLocationSource(locationSource)
|
||||
map.setOnMapLongClickListener(locationSource)
|
||||
if (ActivityCompat.checkSelfPermission(this, permission.ACCESS_FINE_LOCATION)
|
||||
!= PackageManager.PERMISSION_GRANTED
|
||||
&& ActivityCompat.checkSelfPermission(this, permission.ACCESS_COARSE_LOCATION)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
return
|
||||
}
|
||||
map.isMyLocationEnabled = true
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A [LocationSource] which reports a new location whenever a user long presses the map
|
||||
* at
|
||||
* the point at which a user long pressed the map.
|
||||
*/
|
||||
private class LongPressLocationSource : LocationSource, OnMapLongClickListener, LifecycleObserver {
|
||||
|
||||
private var listener: OnLocationChangedListener? = null
|
||||
|
||||
/**
|
||||
* Flag to keep track of the activity's lifecycle. This is not strictly necessary in this
|
||||
* case because onMapLongPress events don't occur while the activity containing the map is
|
||||
* paused but is included to demonstrate best practices (e.g., if a background service were
|
||||
* to be used).
|
||||
*/
|
||||
private var paused = false
|
||||
|
||||
override fun activate(listener: OnLocationChangedListener) {
|
||||
this.listener = listener
|
||||
}
|
||||
|
||||
override fun deactivate() {
|
||||
listener = null
|
||||
}
|
||||
|
||||
override fun onMapLongClick(point: LatLng) {
|
||||
if (paused) {
|
||||
return
|
||||
}
|
||||
|
||||
val location = Location("LongPressLocationProvider")
|
||||
location.latitude = point.latitude
|
||||
location.longitude = point.longitude
|
||||
location.accuracy = 100f
|
||||
listener?.onLocationChanged(location)
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||
fun onPause() {
|
||||
paused = true
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
fun onResume() {
|
||||
paused = false
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright 2018 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.kotlindemos
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.example.kotlindemos.OnMapAndViewReadyListener.OnGlobalLayoutAndMapReadyListener
|
||||
import com.google.android.gms.maps.CameraUpdateFactory
|
||||
import com.google.android.gms.maps.GoogleMap
|
||||
import com.google.android.gms.maps.SupportMapFragment
|
||||
import com.google.android.gms.maps.model.LatLng
|
||||
import com.google.android.gms.maps.model.LatLngBounds
|
||||
import com.google.android.gms.maps.model.Marker
|
||||
import com.google.android.gms.maps.model.MarkerOptions
|
||||
|
||||
|
||||
/**
|
||||
* This shows how to close the info window when the currently selected marker is re-tapped.
|
||||
*/
|
||||
class MarkerCloseInfoWindowOnRetapDemoActivity :
|
||||
AppCompatActivity(),
|
||||
OnGlobalLayoutAndMapReadyListener {
|
||||
|
||||
private lateinit var map: GoogleMap
|
||||
|
||||
/** Keeps track of the selected marker. It will be set to null if no marker is selected. */
|
||||
private var selectedMarker: Marker? = null
|
||||
|
||||
/**
|
||||
* If user tapped on the the marker which was already showing info window,
|
||||
* the showing info window will be closed. Otherwise will show a different window.
|
||||
*/
|
||||
private val markerClickListener = object : GoogleMap.OnMarkerClickListener {
|
||||
override fun onMarkerClick(marker: Marker?): Boolean {
|
||||
if (marker == selectedMarker) {
|
||||
selectedMarker = null
|
||||
// Return true to indicate we have consumed the event and that we do not
|
||||
// want the the default behavior to occur (which is for the camera to move
|
||||
// such that the marker is centered and for the marker's info window to open,
|
||||
// if it has one).
|
||||
return true
|
||||
}
|
||||
|
||||
selectedMarker = marker
|
||||
// Return false to indicate that we have not consumed the event and that
|
||||
// we wish for the default behavior to occur.
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_marker_close_info_window_on_retap_demo)
|
||||
|
||||
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
|
||||
OnMapAndViewReadyListener(mapFragment, this)
|
||||
}
|
||||
|
||||
override fun onMapReady(googleMap: GoogleMap?) {
|
||||
// Return if googleMap was null
|
||||
map = googleMap ?: return
|
||||
|
||||
with(map) {
|
||||
uiSettings.isZoomControlsEnabled = false
|
||||
|
||||
setOnMarkerClickListener(markerClickListener)
|
||||
|
||||
// Set listener for map click event. Any showing info window closes
|
||||
// when the map is clicked. Clear the currently selected marker.
|
||||
setOnMapClickListener { selectedMarker = null }
|
||||
|
||||
setContentDescription(getString(R.string.close_info_window_demo_details))
|
||||
|
||||
// Add markers to different cities in Australia and include it in bounds
|
||||
val bounds = LatLngBounds.Builder()
|
||||
cities.map { city ->
|
||||
addMarker(MarkerOptions().apply {
|
||||
position(city.latLng)
|
||||
title(city.title)
|
||||
snippet(city.snippet)
|
||||
})
|
||||
bounds.include(city.latLng)
|
||||
}
|
||||
|
||||
moveCamera(CameraUpdateFactory.newLatLngBounds(bounds.build(), 50))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to contain information about a marker.
|
||||
*
|
||||
* @property latLng latitude and longitude of the marker
|
||||
* @property title a string containing the city name
|
||||
* @property snippet a string containing the population of the city
|
||||
*/
|
||||
class MarkerInfo(val latLng: LatLng, val title: String, val snippet: String)
|
||||
|
||||
private val cities = listOf(
|
||||
MarkerInfo(LatLng(-27.47093, 153.0235),
|
||||
"Brisbane", "Population: 2,074,200"),
|
||||
MarkerInfo(LatLng(-37.81319, 144.96298),
|
||||
"Melbourne", "Population: 4,137,400"),
|
||||
MarkerInfo(LatLng(-33.87365, 151.20689),
|
||||
"Sydney", "Population: 4,627,300"),
|
||||
MarkerInfo(LatLng(-34.92873, 138.59995),
|
||||
"Adelaide", "Population: 1,213,000"),
|
||||
MarkerInfo(LatLng(-31.952854, 115.857342),
|
||||
"Perth", "Population: 1,738,800")
|
||||
)
|
||||
}
|
||||
@ -54,7 +54,7 @@ class TileOverlayDemoActivity : AppCompatActivity(), OnSeekBarChangeListener, On
|
||||
map.mapType = GoogleMap.MAP_TYPE_NONE
|
||||
val tileProvider: TileProvider = object : UrlTileProvider(256, 256) {
|
||||
@Synchronized
|
||||
override fun getTileUrl(x: Int, y: Int, zoom: Int): URL {
|
||||
override fun getTileUrl(x: Int, y: Int, zoom: Int): URL? {
|
||||
// The moon tile coordinate system is reversed. This is not normal.
|
||||
val reversedY = (1 shl zoom) - y - 1
|
||||
val s = String.format(Locale.US, MOON_MAP_URL_FORMAT, zoom, x, reversedY)
|
||||
|
||||
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2016 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:map="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<Button
|
||||
android:id="@+id/clamp_min_zoom"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/clamp_min_zoom"/>
|
||||
<Button
|
||||
android:id="@+id/clamp_max_zoom"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/clamp_max_zoom"/>
|
||||
<Button
|
||||
android:id="@+id/clamp_zoom_reset"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/clamp_zoom_reset"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<Button
|
||||
android:id="@+id/clamp_latlng_adelaide"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.5"
|
||||
android:text="@string/clamp_latlng_adelaide"/>
|
||||
<Button
|
||||
android:id="@+id/clamp_latlng_pacific"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.5"
|
||||
android:text="@string/clamp_latlng_pacific"/>
|
||||
<Button
|
||||
android:id="@+id/clamp_latlng_reset"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/clamp_latlng_reset"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:id="@+id/camera_text"
|
||||
android:text="@string/move_the_camera"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<fragment
|
||||
android:id="@+id/map"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
class="com.google.android.gms.maps.SupportMapFragment"
|
||||
map:cameraMinZoomPreference="10.0"
|
||||
map:cameraMaxZoomPreference="14.0"
|
||||
map:latLngBoundsSouthWestLatitude="37.4"
|
||||
map:latLngBoundsSouthWestLongitude="-122.1"
|
||||
map:latLngBoundsNorthEastLatitude="37.45"
|
||||
map:latLngBoundsNorthEastLongitude="-122.05"
|
||||
map:cameraTargetLat="37.421976"
|
||||
map:cameraTargetLng="-122.084065"
|
||||
map:cameraZoom="12"/>
|
||||
</LinearLayout>
|
||||
@ -13,7 +13,7 @@
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<resources>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<string name="app_name">Maps SDK for Android Demos (Kotlin)</string>
|
||||
<string name="demo_title">Google Maps API Demos</string>
|
||||
<string name="no_demos">No demos</string>
|
||||
@ -274,4 +274,19 @@
|
||||
<!-- Marker Collision -->
|
||||
<string name="marker_collision_label">Marker Collision</string>
|
||||
<string name="marker_collision_description">Demonstrates different supported marker collision behaviors.</string>
|
||||
|
||||
<!-- Camera Clamping -->
|
||||
<string name="camera_clamping_demo_label">Camera Clamping</string>
|
||||
<string name="camera_clamping_demo_description">Demonstrates how to constrain the camera to specific boundaries and zoom levels.</string>
|
||||
<string name="clamp_latlng_adelaide">Clamp to Adelaide</string>
|
||||
<string name="clamp_latlng_pacific">Clamp to Pacific</string>
|
||||
<string name="clamp_latlng_reset">Reset LatLng Bounds</string>
|
||||
<string name="clamp_min_zoom">MinZoom++</string>
|
||||
<string name="clamp_max_zoom" tools:ignore="TypographyDashes">MaxZoom--</string>
|
||||
<string name="clamp_zoom_reset">Reset Zoom Bounds</string>
|
||||
|
||||
<!-- Location Source -->
|
||||
<string name="location_source_demo_label">Location Source Demo</string>
|
||||
<string name="location_source_demo_description">Demonstrates how to use a custom location source.</string>
|
||||
|
||||
</resources>
|
||||
@ -34,7 +34,7 @@
|
||||
<activity android:name=".BasicMapDemoActivity" />
|
||||
<activity android:name=".CameraDemoActivity"/>
|
||||
<activity android:name=".CircleDemoActivity" />
|
||||
<activity android:name=".CloseInfoWindowDemoActivity" />
|
||||
<activity android:name=".MarkerCloseInfoWindowOnRetapDemoActivity" />
|
||||
<activity android:name=".CloudBasedMapStylingDemoActivity" />
|
||||
<activity android:name=".EventsDemoActivity" />
|
||||
<activity android:name=".GroundOverlayDemoActivity" />
|
||||
|
||||
@ -0,0 +1,131 @@
|
||||
/**
|
||||
* DO NOT EDIT THIS FILE.
|
||||
*
|
||||
* This source code was autogenerated from source code within the `app/src/gms` directory
|
||||
* and is not intended for modifications. If any edits should be made, please do so in the
|
||||
* corresponding file under the `app/src/gms` directory.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2018 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.kotlindemos
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.example.kotlindemos.OnMapAndViewReadyListener.OnGlobalLayoutAndMapReadyListener
|
||||
import com.google.android.libraries.maps.CameraUpdateFactory
|
||||
import com.google.android.libraries.maps.GoogleMap
|
||||
import com.google.android.libraries.maps.SupportMapFragment
|
||||
import com.google.android.libraries.maps.model.LatLng
|
||||
import com.google.android.libraries.maps.model.LatLngBounds
|
||||
import com.google.android.libraries.maps.model.Marker
|
||||
import com.google.android.libraries.maps.model.MarkerOptions
|
||||
|
||||
|
||||
/**
|
||||
* This shows how to close the info window when the currently selected marker is re-tapped.
|
||||
*/
|
||||
class MarkerCloseInfoWindowOnRetapDemoActivity :
|
||||
AppCompatActivity(),
|
||||
OnGlobalLayoutAndMapReadyListener {
|
||||
|
||||
private lateinit var map: GoogleMap
|
||||
|
||||
/** Keeps track of the selected marker. It will be set to null if no marker is selected. */
|
||||
private var selectedMarker: Marker? = null
|
||||
|
||||
/**
|
||||
* If user tapped on the the marker which was already showing info window,
|
||||
* the showing info window will be closed. Otherwise will show a different window.
|
||||
*/
|
||||
private val markerClickListener = object : GoogleMap.OnMarkerClickListener {
|
||||
override fun onMarkerClick(marker: Marker?): Boolean {
|
||||
if (marker == selectedMarker) {
|
||||
selectedMarker = null
|
||||
// Return true to indicate we have consumed the event and that we do not
|
||||
// want the the default behavior to occur (which is for the camera to move
|
||||
// such that the marker is centered and for the marker's info window to open,
|
||||
// if it has one).
|
||||
return true
|
||||
}
|
||||
|
||||
selectedMarker = marker
|
||||
// Return false to indicate that we have not consumed the event and that
|
||||
// we wish for the default behavior to occur.
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_marker_close_info_window_on_retap_demo)
|
||||
|
||||
val mapFragment = supportFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
|
||||
OnMapAndViewReadyListener(mapFragment, this)
|
||||
}
|
||||
|
||||
override fun onMapReady(googleMap: GoogleMap?) {
|
||||
// Return if googleMap was null
|
||||
map = googleMap ?: return
|
||||
|
||||
with(map) {
|
||||
uiSettings.isZoomControlsEnabled = false
|
||||
|
||||
setOnMarkerClickListener(markerClickListener)
|
||||
|
||||
// Set listener for map click event. Any showing info window closes
|
||||
// when the map is clicked. Clear the currently selected marker.
|
||||
setOnMapClickListener { selectedMarker = null }
|
||||
|
||||
setContentDescription(getString(R.string.close_info_window_demo_details))
|
||||
|
||||
// Add markers to different cities in Australia and include it in bounds
|
||||
val bounds = LatLngBounds.Builder()
|
||||
cities.map { city ->
|
||||
addMarker(MarkerOptions().apply {
|
||||
position(city.latLng)
|
||||
title(city.title)
|
||||
snippet(city.snippet)
|
||||
})
|
||||
bounds.include(city.latLng)
|
||||
}
|
||||
|
||||
moveCamera(CameraUpdateFactory.newLatLngBounds(bounds.build(), 50))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to contain information about a marker.
|
||||
*
|
||||
* @property latLng latitude and longitude of the marker
|
||||
* @property title a string containing the city name
|
||||
* @property snippet a string containing the population of the city
|
||||
*/
|
||||
class MarkerInfo(val latLng: LatLng, val title: String, val snippet: String)
|
||||
|
||||
private val cities = listOf(
|
||||
MarkerInfo(LatLng(-27.47093, 153.0235),
|
||||
"Brisbane", "Population: 2,074,200"),
|
||||
MarkerInfo(LatLng(-37.81319, 144.96298),
|
||||
"Melbourne", "Population: 4,137,400"),
|
||||
MarkerInfo(LatLng(-33.87365, 151.20689),
|
||||
"Sydney", "Population: 4,627,300"),
|
||||
MarkerInfo(LatLng(-34.92873, 138.59995),
|
||||
"Adelaide", "Population: 1,213,000"),
|
||||
MarkerInfo(LatLng(-31.952854, 115.857342),
|
||||
"Perth", "Population: 1,738,800")
|
||||
)
|
||||
}
|
||||
@ -61,7 +61,7 @@ class TileOverlayDemoActivity : AppCompatActivity(), OnSeekBarChangeListener, On
|
||||
map.mapType = GoogleMap.MAP_TYPE_NONE
|
||||
val tileProvider: TileProvider = object : UrlTileProvider(256, 256) {
|
||||
@Synchronized
|
||||
override fun getTileUrl(x: Int, y: Int, zoom: Int): URL {
|
||||
override fun getTileUrl(x: Int, y: Int, zoom: Int): URL? {
|
||||
// The moon tile coordinate system is reversed. This is not normal.
|
||||
val reversedY = (1 shl zoom) - y - 1
|
||||
val s = String.format(Locale.US, MOON_MAP_URL_FORMAT, zoom, x, reversedY)
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.72'
|
||||
ext.kotlin_version = '1.4.10'
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.0.1'
|
||||
classpath 'com.android.tools.build:gradle:4.1.2'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#Mon Jul 27 17:09:41 PDT 2020
|
||||
#Mon Jan 25 11:17:39 PST 2021
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user