Commit c6392894 authored by Qiu Xiang's avatar Qiu Xiang

Fix #42: Android locationEnabled bug

parent 0b9fa6ec
...@@ -20,15 +20,16 @@ class AMapView(context: Context) : TextureMapView(context) { ...@@ -20,15 +20,16 @@ class AMapView(context: Context) : TextureMapView(context) {
private val polylines = HashMap<String, AMapPolyline>() private val polylines = HashMap<String, AMapPolyline>()
private val polygons = HashMap<String, AMapPolygon>() private val polygons = HashMap<String, AMapPolygon>()
private val circles = HashMap<String, AMapCircle>() private val circles = HashMap<String, AMapCircle>()
private var locationType = MyLocationStyle.LOCATION_TYPE_FOLLOW_NO_CENTER
private val locationStyle by lazy {
val locationStyle = MyLocationStyle()
locationStyle.myLocationType(locationType)
locationStyle
}
init { init {
super.onCreate(null) super.onCreate(null)
// 设置默认的定位模式
val locationStyle = MyLocationStyle()
locationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER)
map.myLocationStyle = locationStyle
map.setOnMapClickListener { latLng -> map.setOnMapClickListener { latLng ->
for (marker in markers.values) { for (marker in markers.values) {
marker.active = false marker.active = false
...@@ -214,4 +215,9 @@ class AMapView(context: Context) : TextureMapView(context) { ...@@ -214,4 +215,9 @@ class AMapView(context: Context) : TextureMapView(context) {
LatLng(latitude + latitudeDelta / 2, longitude + longitudeDelta / 2) LatLng(latitude + latitudeDelta / 2, longitude + longitudeDelta / 2)
)) ))
} }
fun setLocationEnabled(enabled: Boolean) {
map.myLocationStyle = locationStyle
map.isMyLocationEnabled = enabled
}
} }
...@@ -4,6 +4,7 @@ import android.view.View ...@@ -4,6 +4,7 @@ import android.view.View
import com.amap.api.maps.AMap import com.amap.api.maps.AMap
import com.amap.api.maps.CameraUpdateFactory import com.amap.api.maps.CameraUpdateFactory
import com.amap.api.maps.model.LatLng import com.amap.api.maps.model.LatLng
import com.amap.api.maps.model.MyLocationStyle
import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap import com.facebook.react.bridge.ReadableMap
import com.facebook.react.common.MapBuilder import com.facebook.react.common.MapBuilder
...@@ -69,7 +70,7 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() { ...@@ -69,7 +70,7 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() {
@ReactProp(name = "locationEnabled") @ReactProp(name = "locationEnabled")
fun setMyLocationEnabled(view: AMapView, enabled: Boolean) { fun setMyLocationEnabled(view: AMapView, enabled: Boolean) {
view.map.isMyLocationEnabled = enabled view.setLocationEnabled(enabled)
} }
@ReactProp(name = "showsIndoorMap") @ReactProp(name = "showsIndoorMap")
......
import React, {Component} from 'react' import React, {Component} from 'react'
import {StyleSheet, View, Text, Switch} from 'react-native' import {StyleSheet, Switch, Text, View} from 'react-native'
import MapView from 'react-native-amap3d' import MapView from 'react-native-amap3d'
import styles from '../styles' import styles from '../styles'
...@@ -48,7 +48,7 @@ export default class Controls extends Component { ...@@ -48,7 +48,7 @@ export default class Controls extends Component {
</View> </View>
</View> </View>
<MapView <MapView
locationEnabled={true} locationEnabled={this.state.showsLocationButton}
showsCompass={this.state.showsCompass} showsCompass={this.state.showsCompass}
showsScale={this.state.showsScale} showsScale={this.state.showsScale}
showsLocationButton={this.state.showsLocationButton} showsLocationButton={this.state.showsLocationButton}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment