From 1f728dfd9be159cb4e3fe0b7b79cdd07d6833e8d Mon Sep 17 00:00:00 2001 From: Bella Mangunsong Date: Tue, 9 Jan 2018 15:53:57 +1100 Subject: [PATCH] Add a Basic Map Demo --- ApiDemos/kotlin/app/build.gradle | 3 + .../src/debug/res/values/google_maps_api.xml | 17 ++++++ .../kotlin/app/src/main/AndroidManifest.xml | 5 ++ .../kotlindemos/BasicMapDemoActivity.kt | 57 +++++++++++++++++++ .../example/kotlindemos/DemoDetailsList.kt | 5 +- .../res/layout/activity_basic_map_demo.xml | 25 ++++++++ .../app/src/main/res/values/strings.xml | 5 ++ 7 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 ApiDemos/kotlin/app/src/debug/res/values/google_maps_api.xml create mode 100644 ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/BasicMapDemoActivity.kt create mode 100644 ApiDemos/kotlin/app/src/main/res/layout/activity_basic_map_demo.xml diff --git a/ApiDemos/kotlin/app/build.gradle b/ApiDemos/kotlin/app/build.gradle index d7aba0ca..507cd986 100644 --- a/ApiDemos/kotlin/app/build.gradle +++ b/ApiDemos/kotlin/app/build.gradle @@ -22,6 +22,7 @@ android { } } + dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" @@ -30,5 +31,7 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' + implementation 'com.google.android.gms:play-services-maps:11.8.0' + compile 'com.google.android.gms:play-services-location:11.8.0' } \ No newline at end of file diff --git a/ApiDemos/kotlin/app/src/debug/res/values/google_maps_api.xml b/ApiDemos/kotlin/app/src/debug/res/values/google_maps_api.xml new file mode 100644 index 00000000..e2924af4 --- /dev/null +++ b/ApiDemos/kotlin/app/src/debug/res/values/google_maps_api.xml @@ -0,0 +1,17 @@ + + + + ADD_YOUR_KEY_HERE + + diff --git a/ApiDemos/kotlin/app/src/main/AndroidManifest.xml b/ApiDemos/kotlin/app/src/main/AndroidManifest.xml index 2d16c4c9..554fb6d9 100644 --- a/ApiDemos/kotlin/app/src/main/AndroidManifest.xml +++ b/ApiDemos/kotlin/app/src/main/AndroidManifest.xml @@ -23,6 +23,10 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> + + @@ -30,6 +34,7 @@ + \ No newline at end of file diff --git a/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/BasicMapDemoActivity.kt b/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/BasicMapDemoActivity.kt new file mode 100644 index 00000000..fda018cf --- /dev/null +++ b/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/BasicMapDemoActivity.kt @@ -0,0 +1,57 @@ +/* + * 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.support.v7.app.AppCompatActivity +import android.os.Bundle + +import com.google.android.gms.maps.CameraUpdateFactory +import com.google.android.gms.maps.GoogleMap +import com.google.android.gms.maps.OnMapReadyCallback +import com.google.android.gms.maps.SupportMapFragment +import com.google.android.gms.maps.model.LatLng +import com.google.android.gms.maps.model.MarkerOptions + +/** + * This shows how to create a simple activity with a map and a marker on the map. + */ +class BasicMapDemoActivity : + AppCompatActivity(), + OnMapReadyCallback { + + val SYDNEY = LatLng(-33.862, 151.21) + val ZOOM_LEVEL = 13f + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_basic_map_demo) + val mapFragment : SupportMapFragment? = + supportFragmentManager.findFragmentById(R.id.map) as? SupportMapFragment + mapFragment?.getMapAsync(this) + } + + /** + * This is where we can add markers or lines, add listeners or move the camera. In this case, + * we just move the camera to Sydney and add a marker in Sydney. + */ + override fun onMapReady(googleMap: GoogleMap) { + with(googleMap) { + moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, ZOOM_LEVEL)) + addMarker(MarkerOptions().position(SYDNEY)) + } + } +} diff --git a/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/DemoDetailsList.kt b/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/DemoDetailsList.kt index 901f7f4e..0d71a3b1 100644 --- a/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/DemoDetailsList.kt +++ b/ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/DemoDetailsList.kt @@ -21,6 +21,9 @@ package com.example.kotlindemos */ class DemoDetailsList { companion object { - val DEMOS = listOf() + val DEMOS = listOf( + DemoDetails(R.string.basic_demo_label, R.string.basic_demo_details, + BasicMapDemoActivity::class.java) + ) } } \ No newline at end of file diff --git a/ApiDemos/kotlin/app/src/main/res/layout/activity_basic_map_demo.xml b/ApiDemos/kotlin/app/src/main/res/layout/activity_basic_map_demo.xml new file mode 100644 index 00000000..17225bd4 --- /dev/null +++ b/ApiDemos/kotlin/app/src/main/res/layout/activity_basic_map_demo.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/ApiDemos/kotlin/app/src/main/res/values/strings.xml b/ApiDemos/kotlin/app/src/main/res/values/strings.xml index 22db8efe..918ce5be 100644 --- a/ApiDemos/kotlin/app/src/main/res/values/strings.xml +++ b/ApiDemos/kotlin/app/src/main/res/values/strings.xml @@ -18,4 +18,9 @@ Google Maps API Demos No demos Google Play services is not installed on this device. + + + Basic Map + Launches a map with marker pointing at Sydney + \ No newline at end of file