Skip to content

Commit 1f728df

Browse files
committed
Add a Basic Map Demo
1 parent a6a20ab commit 1f728df

File tree

7 files changed

+116
-1
lines changed

7 files changed

+116
-1
lines changed

ApiDemos/kotlin/app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ android {
2222
}
2323
}
2424

25+
2526
dependencies {
2627
implementation fileTree(dir: 'libs', include: ['*.jar'])
2728
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
@@ -30,5 +31,7 @@ dependencies {
3031
testImplementation 'junit:junit:4.12'
3132
androidTestImplementation 'com.android.support.test:runner:1.0.1'
3233
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
34+
implementation 'com.google.android.gms:play-services-maps:11.8.0'
35+
compile 'com.google.android.gms:play-services-location:11.8.0'
3336

3437
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<resources>
2+
<!--
3+
TODO: Before you run your application, you need a Google Maps API key.
4+
5+
See this page for more information:
6+
https://developers.google.com/maps/documentation/android/start#get_an_android_certificate_and_the_google_maps_api_key
7+
8+
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
9+
string in this file.
10+
11+
Note: This resource is used for the debug build target. Update this file if you just want to run
12+
the demo app.
13+
-->
14+
<string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">
15+
ADD_YOUR_KEY_HERE
16+
</string>
17+
</resources>

ApiDemos/kotlin/app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@
2323
android:roundIcon="@mipmap/ic_launcher_round"
2424
android:supportsRtl="true"
2525
android:theme="@style/AppTheme">
26+
<meta-data
27+
android:name="com.google.android.geo.API_KEY"
28+
android:value="@string/google_maps_key" />
29+
2630
<activity android:name=".MainActivity">
2731
<intent-filter>
2832
<action android:name="android.intent.action.MAIN" />
2933

3034
<category android:name="android.intent.category.LAUNCHER" />
3135
</intent-filter>
3236
</activity>
37+
<activity android:name=".BasicMapDemoActivity"></activity>
3338
</application>
3439

3540
</manifest>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.kotlindemos
18+
19+
import android.support.v7.app.AppCompatActivity
20+
import android.os.Bundle
21+
22+
import com.google.android.gms.maps.CameraUpdateFactory
23+
import com.google.android.gms.maps.GoogleMap
24+
import com.google.android.gms.maps.OnMapReadyCallback
25+
import com.google.android.gms.maps.SupportMapFragment
26+
import com.google.android.gms.maps.model.LatLng
27+
import com.google.android.gms.maps.model.MarkerOptions
28+
29+
/**
30+
* This shows how to create a simple activity with a map and a marker on the map.
31+
*/
32+
class BasicMapDemoActivity :
33+
AppCompatActivity(),
34+
OnMapReadyCallback {
35+
36+
val SYDNEY = LatLng(-33.862, 151.21)
37+
val ZOOM_LEVEL = 13f
38+
39+
override fun onCreate(savedInstanceState: Bundle?) {
40+
super.onCreate(savedInstanceState)
41+
setContentView(R.layout.activity_basic_map_demo)
42+
val mapFragment : SupportMapFragment? =
43+
supportFragmentManager.findFragmentById(R.id.map) as? SupportMapFragment
44+
mapFragment?.getMapAsync(this)
45+
}
46+
47+
/**
48+
* This is where we can add markers or lines, add listeners or move the camera. In this case,
49+
* we just move the camera to Sydney and add a marker in Sydney.
50+
*/
51+
override fun onMapReady(googleMap: GoogleMap) {
52+
with(googleMap) {
53+
moveCamera(CameraUpdateFactory.newLatLngZoom(SYDNEY, ZOOM_LEVEL))
54+
addMarker(MarkerOptions().position(SYDNEY))
55+
}
56+
}
57+
}

ApiDemos/kotlin/app/src/main/java/com/example/kotlindemos/DemoDetailsList.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ package com.example.kotlindemos
2121
*/
2222
class DemoDetailsList {
2323
companion object {
24-
val DEMOS = listOf<DemoDetails>()
24+
val DEMOS = listOf<DemoDetails>(
25+
DemoDetails(R.string.basic_demo_label, R.string.basic_demo_details,
26+
BasicMapDemoActivity::class.java)
27+
)
2528
}
2629
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2018 Google LLC
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:tools="http://schemas.android.com/tools"
19+
android:id="@+id/map"
20+
android:name="com.google.android.gms.maps.SupportMapFragment"
21+
android:layout_width="match_parent"
22+
android:layout_height="match_parent"
23+
tools:context="com.example.kotlindemos.BasicMapDemoActivity">
24+
25+
</fragment>

ApiDemos/kotlin/app/src/main/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@
1818
<string name="demo_title">Google Maps API Demos</string>
1919
<string name="no_demos">No demos</string>
2020
<string name="play_services_not_installed">Google Play services is not installed on this device.</string>
21+
22+
<!-- Basic Map Demo -->
23+
<string name="basic_demo_label">Basic Map</string>
24+
<string name="basic_demo_details">Launches a map with marker pointing at Sydney</string>
25+
2126
</resources>

0 commit comments

Comments
 (0)