Add a Basic Map Demo

This commit is contained in:
Bella Mangunsong 2018-01-09 15:53:57 +11:00
parent a6a20ab6ca
commit 1f728dfd9b
7 changed files with 116 additions and 1 deletions

View File

@ -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'
}

View File

@ -0,0 +1,17 @@
<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.
See this page for more information:
https://developers.google.com/maps/documentation/android/start#get_an_android_certificate_and_the_google_maps_api_key
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
Note: This resource is used for the debug build target. Update this file if you just want to run
the demo app.
-->
<string name="google_maps_key" translatable="false" templateMergeStrategy="preserve">
ADD_YOUR_KEY_HERE
</string>
</resources>

View File

@ -23,6 +23,10 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -30,6 +34,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".BasicMapDemoActivity"></activity>
</application>
</manifest>

View File

@ -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))
}
}
}

View File

@ -21,6 +21,9 @@ package com.example.kotlindemos
*/
class DemoDetailsList {
companion object {
val DEMOS = listOf<DemoDetails>()
val DEMOS = listOf<DemoDetails>(
DemoDetails(R.string.basic_demo_label, R.string.basic_demo_details,
BasicMapDemoActivity::class.java)
)
}
}

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.kotlindemos.BasicMapDemoActivity">
</fragment>

View File

@ -18,4 +18,9 @@
<string name="demo_title">Google Maps API Demos</string>
<string name="no_demos">No demos</string>
<string name="play_services_not_installed">Google Play services is not installed on this device.</string>
<!-- Basic Map Demo -->
<string name="basic_demo_label">Basic Map</string>
<string name="basic_demo_details">Launches a map with marker pointing at Sydney</string>
</resources>