【发布时间】:2019-08-10 07:32:43
【问题描述】:
我想在我的 android 应用中使用 Neshan 地图平台。但地图不会加载到模拟器上,只显示徽标。
这是清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.neshantest2">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:hardwareAccelerated="true">
<activity android:name=".routing.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
这是 gradle 项目级别: 顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项。
buildscript {
ext.kotlin_version = '1.3.21'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://dl.bintray.com/neshan/neshan-android-sdk" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
这是 gradle 模块级别
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.neshantest2"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
splits {
abi {
enable true
reset()
include 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'mips', 'mips64', 'arm64-v8a'
universalApk false
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'neshan-android-sdk:mobile-sdk:0.9.5'
///////////retrofit
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
}
这是主要的活动类:
package com.example.neshantest2.routing
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import com.example.neshantest2.R
import com.example.neshantest2.services.dataServices
import kotlinx.android.synthetic.main.activity_main.*
import org.neshan.core.Bounds
import org.neshan.core.LngLat
import org.neshan.core.LngLatVector
import org.neshan.core.Range
import org.neshan.geometry.LineGeom
import org.neshan.graphics.ARGB
import org.neshan.layers.VectorElementLayer
import org.neshan.services.NeshanMapStyle
import org.neshan.services.NeshanServices
import org.neshan.styles.*
import org.neshan.vectorelements.Line
const val BASE_MAP_INDEX = 0
class MainActivity : AppCompatActivity(),
RoutingInterface.RoutingViewInterface{
var presenter: RoutingInterface.RoutingPresenterInterface? = null
private lateinit var lineLayer: VectorElementLayer
private lateinit var markerLayer: VectorElementLayer
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
presenter = RoutingPresenter(applicationContext,this) //initial
presenter
}
fun requestBtnClicked(view: View?) {
//add origin and dest coordinates
dataServices.originCoordinates = Pair(originx.text.toString(), originy.text.toString())
dataServices.destinationCoordinates = Pair(destinationX.text.toString(), destinationY.text.toString())
//add waypoints
dataServices.waypoints += Pair(waypoint1x.text.toString(), waypoint1y.text.toString())
dataServices.waypoints += Pair(waypoint2x.text.toString(), waypoint2y.text.toString())
dataServices.waypoints += Pair(waypoint3x.text.toString(), waypoint3y.text.toString())
//call APIs
presenter!!.sendDistanceReq()
presenter!!.sendDirectionReq()
showmapbutton.visibility = View.VISIBLE
}
fun showRoutesClicked(view: View?) {
mapInit()
drawRoute()
}
override fun mapInit() {
scrollview.visibility = View.GONE
map.visibility = View.VISIBLE
markerLayer = NeshanServices.createVectorElementLayer()
lineLayer = NeshanServices.createVectorElementLayer()
map.layers.add(markerLayer)
map.layers.add(lineLayer)
//set map focus position
map.setFocalPointPosition(
LngLat(
dataServices.originCoordinates.second.toDouble(),
dataServices.originCoordinates.first.toDouble()
), 0f
)
map.setZoom(16f, 0f)
map.options.setZoomRange(Range(4.5f, 16f))
map.layers.insert(BASE_MAP_INDEX,
NeshanServices.createBaseMap(NeshanMapStyle.STANDARD_DAY))
setMapBounds()
}
override fun drawLineGeom(org: LngLat, dest: LngLat): LineGeom {
val lngLatVector = LngLatVector()
lngLatVector.add(org)
lngLatVector.add(dest)
val lineGeom = LineGeom(lngLatVector)
val line = Line(lineGeom, getLineStyle())
lineLayer.add(line)
return lineGeom
}
override fun drawRoute() {
lineLayer.clear()
for (i in 0..dataServices.routeCoordinates.count() - 2) {
drawLineGeom(
LngLat(dataServices.routeCoordinates[i].longitude, dataServices.routeCoordinates[i].latitude),
LngLat(dataServices.routeCoordinates[i + 1].longitude, dataServices.routeCoordinates[i + 1].latitude)
)
}
}
override fun getLineStyle(): LineStyle {
val builder = LineStyleCreator()
builder.color = ARGB(2, 119, 189, 190)
builder.width = 12f
builder.stretchFactor = 0f
return builder.buildStyle()
}
override fun setMapBounds() {
val bounds = Bounds(
LngLat(43.505859, 24.647017),
LngLat(63.984375, 40.178873)
)
map.options.setPanBounds(bounds)
}
override fun showLoading() {
distanceText.text = "Loading..."
durationText.text = "Loading..."
}
override fun showRes() {
distanceText.text = "Distance : " + dataServices.responseDistance.getText()
durationText.text = "Duration : " + dataServices.responseDuration.getText()
}
}
【问题讨论】:
-
可能值得在他们的 github 上提出一个问题(假设他们有一个)而不是在这里问
标签: android google-maps kotlin neshan-platform neshan-map