mirror of
https://github.com/googlemaps/android-samples.git
synced 2025-12-08 18:02:20 +00:00
Merge pull request #90 from katherineallen/master
addresses comments from #87
This commit is contained in:
commit
78bbc34b37
@ -56,8 +56,8 @@ class CameraDemoActivity :
|
||||
private val SCROLL_BY_PX = 100
|
||||
private val TAG = CameraDemoActivity::class.java.name
|
||||
private val sydneyLatLng = LatLng(-33.87365, 151.20689)
|
||||
private val bondiLocation: CameraPosition = CameraPosition.Builder().
|
||||
target(LatLng(-33.891614, 151.276417))
|
||||
private val bondiLocation: CameraPosition = CameraPosition.Builder()
|
||||
.target(LatLng(-33.891614, 151.276417))
|
||||
.zoom(15.5f)
|
||||
.bearing(300f)
|
||||
.tilt(50f)
|
||||
@ -151,16 +151,16 @@ class CameraDemoActivity :
|
||||
checkReadyThen {
|
||||
changeCamera(CameraUpdateFactory.newCameraPosition(sydneyLocation),
|
||||
object : CancelableCallback {
|
||||
override fun onFinish() {
|
||||
Toast.makeText(baseContext, "Animation to Sydney complete",
|
||||
Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
override fun onFinish() {
|
||||
Toast.makeText(baseContext, "Animation to Sydney complete",
|
||||
Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
override fun onCancel() {
|
||||
Toast.makeText(baseContext, "Animation to Sydney canceled",
|
||||
Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
})
|
||||
override fun onCancel() {
|
||||
Toast.makeText(baseContext, "Animation to Sydney canceled",
|
||||
Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -124,13 +124,17 @@ class LayersDemoActivity :
|
||||
|
||||
|
||||
// attach a listener to each checkbox
|
||||
trafficCheckbox.setOnClickListener { map.isTrafficEnabled = trafficCheckbox.isChecked }
|
||||
trafficCheckbox.setOnClickListener {
|
||||
map.isTrafficEnabled = trafficCheckbox.isChecked
|
||||
}
|
||||
|
||||
buildingsCheckbox.setOnClickListener {
|
||||
map.isBuildingsEnabled = buildingsCheckbox.isChecked
|
||||
}
|
||||
|
||||
indoorCheckbox.setOnClickListener { map.isIndoorEnabled = indoorCheckbox.isChecked }
|
||||
indoorCheckbox.setOnClickListener {
|
||||
map.isIndoorEnabled = indoorCheckbox.isChecked
|
||||
}
|
||||
|
||||
// if this box is checked, must check for permission before enabling the My Location layer
|
||||
myLocationCheckbox.setOnClickListener {
|
||||
|
||||
@ -59,19 +59,6 @@ import com.google.android.gms.maps.model.MarkerOptions
|
||||
import java.util.ArrayList
|
||||
import java.util.Random
|
||||
|
||||
/**
|
||||
* This stores the details of a place that used to draw a marker
|
||||
*/
|
||||
class PlaceDetails(
|
||||
val position: LatLng,
|
||||
val title: String = "Marker",
|
||||
val snippet: String? = null,
|
||||
val icon: BitmapDescriptor = BitmapDescriptorFactory.defaultMarker(),
|
||||
val infoWindowAnchorX: Float = 0.5F,
|
||||
val infoWindowAnchorY: Float = 0F,
|
||||
val draggable: Boolean = false,
|
||||
val zIndex: Float = 0F)
|
||||
|
||||
/**
|
||||
* This shows how to place markers on a map.
|
||||
*/
|
||||
@ -387,19 +374,6 @@ class MarkerDemoActivity :
|
||||
return BitmapDescriptorFactory.fromBitmap(bitmap)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the map is ready, the executes the provided lambda function
|
||||
*
|
||||
* @param stuffToDo the code to be executed if the map is ready
|
||||
*/
|
||||
private fun checkReadyThen(stuffToDo : () -> Unit) {
|
||||
if (!::map.isInitialized) {
|
||||
Toast.makeText(this, R.string.map_not_ready, Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
stuffToDo()
|
||||
}
|
||||
}
|
||||
|
||||
/** Called when the Clear button is clicked. */
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
fun onClearMap(view: View) {
|
||||
@ -491,4 +465,30 @@ class MarkerDemoActivity :
|
||||
override fun onMarkerDrag(marker : Marker) {
|
||||
topText.text = getString(R.string.on_marker_drag, marker.position.latitude, marker.position.longitude)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the map is ready, the executes the provided lambda function
|
||||
*
|
||||
* @param stuffToDo the code to be executed if the map is ready
|
||||
*/
|
||||
private fun checkReadyThen(stuffToDo : () -> Unit) {
|
||||
if (!::map.isInitialized) {
|
||||
Toast.makeText(this, R.string.map_not_ready, Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
stuffToDo()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This stores the details of a place that used to draw a marker
|
||||
*/
|
||||
class PlaceDetails(
|
||||
val position: LatLng,
|
||||
val title: String = "Marker",
|
||||
val snippet: String? = null,
|
||||
val icon: BitmapDescriptor = BitmapDescriptorFactory.defaultMarker(),
|
||||
val infoWindowAnchorX: Float = 0.5F,
|
||||
val infoWindowAnchorY: Float = 0F,
|
||||
val draggable: Boolean = false,
|
||||
val zIndex: Float = 0F)
|
||||
@ -33,14 +33,14 @@ import com.google.android.gms.maps.SupportMapFragment
|
||||
class OnMapAndViewReadyListener(
|
||||
private val mapFragment: SupportMapFragment,
|
||||
private val toBeNotified: OnGlobalLayoutAndMapReadyListener
|
||||
) : OnGlobalLayoutListener,
|
||||
) : OnGlobalLayoutListener,
|
||||
OnMapReadyCallback {
|
||||
|
||||
private val mapView: View? = mapFragment.view
|
||||
|
||||
private var isViewReady = false
|
||||
private var isMapReady = false
|
||||
private var googleMap: GoogleMap? = null
|
||||
private var map: GoogleMap? = null
|
||||
|
||||
/** A listener that needs to wait for both the GoogleMap and the View to be initialized. */
|
||||
interface OnGlobalLayoutAndMapReadyListener {
|
||||
@ -65,9 +65,9 @@ class OnMapAndViewReadyListener(
|
||||
mapFragment.getMapAsync(this)
|
||||
}
|
||||
|
||||
override fun onMapReady(googleMap: GoogleMap) {
|
||||
override fun onMapReady(googleMap: GoogleMap?) {
|
||||
// NOTE: The GoogleMap API specifies the listener is removed just prior to invocation.
|
||||
this.googleMap = googleMap
|
||||
map = googleMap ?: return
|
||||
isMapReady = true
|
||||
fireCallbackIfReady()
|
||||
}
|
||||
@ -87,7 +87,7 @@ class OnMapAndViewReadyListener(
|
||||
|
||||
private fun fireCallbackIfReady() {
|
||||
if (isViewReady && isMapReady) {
|
||||
toBeNotified.onMapReady(googleMap)
|
||||
toBeNotified.onMapReady(map)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,13 +93,13 @@ class PolylineDemoActivity :
|
||||
|
||||
// These are the options for polyline caps, joints and patterns. We use their
|
||||
// string resource IDs as identifiers.
|
||||
private val capTypeNameResourceIds = intArrayOf(R.string.cap_butt, // Default
|
||||
private val capTypeNameResourceIds = intArrayOf(R.string.cap_butt,
|
||||
R.string.cap_round, R.string.cap_square, R.string.cap_image)
|
||||
|
||||
private val jointTypeNameResourceIds = intArrayOf(R.string.joint_type_default, // Default
|
||||
private val jointTypeNameResourceIds = intArrayOf(R.string.joint_type_default,
|
||||
R.string.joint_type_bevel, R.string.joint_type_round)
|
||||
|
||||
private val patternTypeNameResourceIds = intArrayOf(R.string.pattern_solid, // Default
|
||||
private val patternTypeNameResourceIds = intArrayOf(R.string.pattern_solid,
|
||||
R.string.pattern_dashed, R.string.pattern_dotted, R.string.pattern_mixed)
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -122,20 +122,20 @@ class PolylineDemoActivity :
|
||||
}
|
||||
|
||||
startCapSpinner = findViewById<Spinner>(R.id.startCapSpinner).apply {
|
||||
adapter = ArrayAdapter(
|
||||
this@PolylineDemoActivity, android.R.layout.simple_spinner_item,
|
||||
adapter = ArrayAdapter(this@PolylineDemoActivity,
|
||||
android.R.layout.simple_spinner_item,
|
||||
getResourceStrings(capTypeNameResourceIds))
|
||||
}
|
||||
|
||||
endCapSpinner = findViewById<Spinner>(R.id.endCapSpinner).apply {
|
||||
adapter = ArrayAdapter(
|
||||
this@PolylineDemoActivity, android.R.layout.simple_spinner_item,
|
||||
adapter = ArrayAdapter(this@PolylineDemoActivity,
|
||||
android.R.layout.simple_spinner_item,
|
||||
getResourceStrings(capTypeNameResourceIds))
|
||||
}
|
||||
|
||||
jointTypeSpinner = findViewById<Spinner>(R.id.jointTypeSpinner).apply {
|
||||
adapter = ArrayAdapter(
|
||||
this@PolylineDemoActivity, android.R.layout.simple_spinner_item,
|
||||
adapter = ArrayAdapter(this@PolylineDemoActivity,
|
||||
android.R.layout.simple_spinner_item,
|
||||
getResourceStrings(jointTypeNameResourceIds))
|
||||
}
|
||||
|
||||
@ -184,11 +184,9 @@ class PolylineDemoActivity :
|
||||
}
|
||||
|
||||
// A simple polyline across Australia. This polyline will be mutable.
|
||||
val color = Color.HSVToColor(
|
||||
alphaBar.progress, floatArrayOf(hueBar.progress.toFloat(), 1f, 1f))
|
||||
|
||||
mutablePolyline = googleMap.addPolyline(PolylineOptions().apply{
|
||||
color(color)
|
||||
color(Color.HSVToColor(
|
||||
alphaBar.progress, floatArrayOf(hueBar.progress.toFloat(), 1f, 1f)))
|
||||
width(widthBar.progress.toFloat())
|
||||
clickable(clickabilityCheckbox.isChecked)
|
||||
add(melbourneLatLng, adelaideLatLng, perthLatLng, darwinLatLng)
|
||||
|
||||
@ -131,7 +131,6 @@ class TagsDemoActivity : AppCompatActivity(),
|
||||
|
||||
private fun addObjectsToMap() {
|
||||
with(map) {
|
||||
|
||||
// A circle centered on Adelaide.
|
||||
addCircle(CircleOptions().apply {
|
||||
center(places.getValue("ADELAIDE"))
|
||||
@ -141,7 +140,8 @@ class TagsDemoActivity : AppCompatActivity(),
|
||||
clickable(true)
|
||||
}).run {
|
||||
// add a tag to the circle to count clicks
|
||||
tag = CustomTag("Adelaide circle")
|
||||
//tag = String("Adelaide circle")
|
||||
tag = "hello"
|
||||
}
|
||||
|
||||
// A ground overlay at Sydney.
|
||||
@ -200,15 +200,15 @@ class TagsDemoActivity : AppCompatActivity(),
|
||||
}
|
||||
|
||||
override fun onCircleClick(circle: Circle) {
|
||||
onClick(circle.tag as CustomTag)
|
||||
onClick(circle.tag as? CustomTag ?: return)
|
||||
}
|
||||
|
||||
override fun onGroundOverlayClick(groundOverlay: GroundOverlay) {
|
||||
onClick(groundOverlay.tag as CustomTag)
|
||||
onClick(groundOverlay.tag as? CustomTag ?: return)
|
||||
}
|
||||
|
||||
override fun onMarkerClick(marker: Marker): Boolean {
|
||||
onClick(marker.tag as CustomTag)
|
||||
onClick(marker.tag as? CustomTag ?: return false)
|
||||
// We return true to indicate that we have consumed the event and that we do not wish
|
||||
// for 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).
|
||||
@ -216,11 +216,11 @@ class TagsDemoActivity : AppCompatActivity(),
|
||||
}
|
||||
|
||||
override fun onPolygonClick(polygon: Polygon) {
|
||||
onClick(polygon.tag as CustomTag)
|
||||
onClick(polygon.tag as? CustomTag ?: return)
|
||||
}
|
||||
|
||||
override fun onPolylineClick(polyline: Polyline) {
|
||||
onClick(polyline.tag as CustomTag)
|
||||
onClick(polyline.tag as? CustomTag ?: return)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user