Skip to content

Added initial tutorial prototype #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions android-location-search/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions android-location-search/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
81 changes: 81 additions & 0 deletions android-location-search/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
}

android {
namespace = "com.example.androidlocationsearch"
compileSdk = 35

defaultConfig {
applicationId = "com.example.androidlocationsearch"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}

dependencies {
// Search SDK dependencies
implementation("com.mapbox.search:autofill:2.14.0-beta.1")
implementation("com.mapbox.search:discover:2.14.0-beta.1")
implementation("com.mapbox.search:place-autocomplete:2.14.0-beta.1")
implementation("com.mapbox.search:offline:2.14.0-beta.1")
implementation("com.mapbox.search:mapbox-search-android:2.14.0-beta.1")
implementation("com.mapbox.search:mapbox-search-android-ui:2.14.0-beta.1")
// If you're using compose also add the compose extension
implementation(platform(libs.androidx.compose.bom))
implementation("com.mapbox.extension:maps-compose:11.13.3")
implementation("com.mapbox.maps:android:11.13.3")
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation("androidx.compose.foundation:foundation:1.6.4")
implementation("androidx.compose.ui:ui-text:1.6.4")
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
}
21 changes: 21 additions & 0 deletions android-location-search/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.androidlocationsearch

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.mapsinstallguide", appContext.packageName)
}
}
33 changes: 33 additions & 0 deletions android-location-search/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!-- Include this permission to grab user's general location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!-- Include only if your app benefits from precise location access. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AndroidLocationSearch"
tools:targetApi="31">
<activity
android:name="com.example.androidlocationsearch.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.AndroidLocationSearch">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.example.androidlocationsearch

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.zIndex

import com.mapbox.geojson.Point
import com.mapbox.maps.extension.compose.MapboxMap
import com.mapbox.maps.extension.compose.animation.viewport.rememberMapViewportState
import com.mapbox.maps.extension.compose.annotation.generated.PointAnnotation
import com.mapbox.maps.extension.compose.annotation.rememberIconImage
import com.mapbox.search.autocomplete.PlaceAutocomplete
import com.mapbox.search.result.SearchResult

@OptIn(ExperimentalComposeUiApi::class)

class MainActivity : ComponentActivity() {

private lateinit var placeAutocomplete: PlaceAutocomplete

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

placeAutocomplete = PlaceAutocomplete.create()

setContent {
val selectedResult = remember { mutableStateOf<SearchResult?>(null) }
val mapViewportState = rememberMapViewportState {
setCameraOptions {
center(Point.fromLngLat(-98.0, 39.5))
zoom(2.0)
}
}

Box(Modifier.fillMaxSize()) {
MapboxMap(
Modifier.fillMaxSize(),
mapViewportState = mapViewportState,
scaleBar = {}, // disables the scale bar by rendering nothing
compass = {} // disable the compass
) {

selectedResult.value?.coordinate?.let { coord ->
val marker = rememberIconImage(
key = R.drawable.map_marker,
painter = painterResource(id = R.drawable.map_marker)
)
PointAnnotation(point = coord) {
iconImage = marker
}
}
}

SearchScreen(
mapViewportState = mapViewportState,
onSuggestionSelected = { result ->
selectedResult.value = result
},
modifier = Modifier
.align(Alignment.TopCenter)
.zIndex(1f)
)
}
}
}
}
Loading