expo-gaode-map 1.0.9 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,6 +35,8 @@ class MarkerView(context: Context, appContext: AppContext) : ExpoView(context, a
35
35
  private var marker: Marker? = null
36
36
  private var aMap: AMap? = null
37
37
  private var pendingPosition: LatLng? = null
38
+ private var pendingLatitude: Double? = null // 临时存储纬度
39
+ private var pendingLongitude: Double? = null // 临时存储经度
38
40
  private var iconWidth: Int = 0 // 用于自定义图标的宽度
39
41
  private var iconHeight: Int = 0 // 用于自定义图标的高度
40
42
  private var customViewWidth: Int = 0 // 用于自定义视图(children)的宽度
@@ -76,29 +78,107 @@ class MarkerView(context: Context, appContext: AppContext) : ExpoView(context, a
76
78
  }
77
79
 
78
80
  /**
79
- * 设置标记位置
81
+ * 设置纬度
82
+ */
83
+ fun setLatitude(lat: Double) {
84
+ try {
85
+ // 验证坐标范围
86
+ if (lat < -90 || lat > 90) {
87
+ android.util.Log.e("MarkerView", "❌ 纬度超出有效范围: $lat")
88
+ return
89
+ }
90
+
91
+ android.util.Log.d("MarkerView", "📍 setLatitude: $lat")
92
+ pendingLatitude = lat
93
+
94
+ // 如果经度也已设置,则更新位置
95
+ pendingLongitude?.let { lng ->
96
+ updatePosition(lat, lng)
97
+ }
98
+ } catch (e: Exception) {
99
+ android.util.Log.e("MarkerView", "❌ setLatitude 发生异常", e)
100
+ }
101
+ }
102
+
103
+ /**
104
+ * 设置经度
105
+ */
106
+ fun setLongitude(lng: Double) {
107
+ try {
108
+ // 验证坐标范围
109
+ if (lng < -180 || lng > 180) {
110
+ android.util.Log.e("MarkerView", "❌ 经度超出有效范围: $lng")
111
+ return
112
+ }
113
+
114
+ android.util.Log.d("MarkerView", "📍 setLongitude: $lng")
115
+ pendingLongitude = lng
116
+
117
+ // 如果纬度也已设置,则更新位置
118
+ pendingLatitude?.let { lat ->
119
+ updatePosition(lat, lng)
120
+ }
121
+ } catch (e: Exception) {
122
+ android.util.Log.e("MarkerView", "❌ setLongitude 发生异常", e)
123
+ }
124
+ }
125
+
126
+ /**
127
+ * 更新标记位置(当经纬度都设置后)
128
+ */
129
+ private fun updatePosition(lat: Double, lng: Double) {
130
+ try {
131
+ val latLng = LatLng(lat, lng)
132
+
133
+ android.util.Log.d("MarkerView", "📍 updatePosition: ($lat, $lng), marker = $marker, aMap = $aMap")
134
+
135
+ marker?.let {
136
+ android.util.Log.d("MarkerView", "✅ 更新现有 marker 位置")
137
+ it.position = latLng
138
+ pendingPosition = null
139
+ pendingLatitude = null
140
+ pendingLongitude = null
141
+ } ?: run {
142
+ android.util.Log.d("MarkerView", "❌ marker 为 null")
143
+ if (aMap != null) {
144
+ android.util.Log.d("MarkerView", "🔧 aMap 存在,创建新 marker")
145
+ createOrUpdateMarker()
146
+ marker?.position = latLng
147
+ pendingLatitude = null
148
+ pendingLongitude = null
149
+ } else {
150
+ android.util.Log.d("MarkerView", "⏳ aMap 为 null,保存位置等待 setMap")
151
+ pendingPosition = latLng
152
+ }
153
+ }
154
+ } catch (e: Exception) {
155
+ android.util.Log.e("MarkerView", "❌ updatePosition 发生异常", e)
156
+ }
157
+ }
158
+
159
+ /**
160
+ * 设置标记位置(兼容旧的 API)
80
161
  */
81
162
  fun setPosition(position: Map<String, Double>) {
82
- val lat = position["latitude"] ?: return
83
- val lng = position["longitude"] ?: return
84
- val latLng = LatLng(lat, lng)
85
-
86
- android.util.Log.d("MarkerView", "📍 setPosition 被调用: ($lat, $lng), marker = $marker, aMap = $aMap")
87
-
88
- marker?.let {
89
- android.util.Log.d("MarkerView", "✅ 更新现有 marker 位置")
90
- it.position = latLng
91
- pendingPosition = null
92
- } ?: run {
93
- android.util.Log.d("MarkerView", "❌ marker null")
94
- if (aMap != null) {
95
- android.util.Log.d("MarkerView", "🔧 aMap 存在,创建新 marker")
96
- createOrUpdateMarker()
97
- marker?.position = latLng
98
- } else {
99
- android.util.Log.d("MarkerView", "⏳ aMap 为 null,保存位置等待 setMap")
100
- pendingPosition = latLng
163
+ try {
164
+ val lat = position["latitude"]
165
+ val lng = position["longitude"]
166
+
167
+ // 验证坐标有效性
168
+ if (lat == null || lng == null) {
169
+ android.util.Log.e("MarkerView", "❌ 无效的位置数据: latitude=$lat, longitude=$lng")
170
+ return
171
+ }
172
+
173
+ // 验证坐标范围
174
+ if (lat < -90 || lat > 90 || lng < -180 || lng > 180) {
175
+ android.util.Log.e("MarkerView", "❌ 坐标超出有效范围: ($lat, $lng)")
176
+ return
101
177
  }
178
+
179
+ updatePosition(lat, lng)
180
+ } catch (e: Exception) {
181
+ android.util.Log.e("MarkerView", "❌ setPosition 发生异常", e)
102
182
  }
103
183
  }
104
184
 
@@ -13,51 +13,56 @@ class MarkerViewModule : Module() {
13
13
  View(MarkerView::class) {
14
14
  Events("onPress", "onDragStart", "onDrag", "onDragEnd")
15
15
 
16
- Prop<Map<String, Double>>("position") { view: MarkerView, position ->
17
- view.setPosition(position)
16
+ // 拆分 position 为两个独立属性以兼容 React Native 旧架构
17
+ Prop<Double>("latitude") { view, lat ->
18
+ view.setLatitude(lat)
18
19
  }
19
20
 
20
- Prop<String>("title") { view: MarkerView, title ->
21
+ Prop<Double>("longitude") { view, lng ->
22
+ view.setLongitude(lng)
23
+ }
24
+
25
+ Prop<String>("title") { view, title ->
21
26
  view.setTitle(title)
22
27
  }
23
28
 
24
- Prop<String>("description") { view: MarkerView, description ->
29
+ Prop<String>("description") { view, description ->
25
30
  view.setDescription(description)
26
31
  }
27
32
 
28
- Prop<Boolean>("draggable") { view: MarkerView, draggable ->
33
+ Prop<Boolean>("draggable") { view, draggable ->
29
34
  view.setDraggable(draggable)
30
35
  }
31
36
 
32
- Prop<Float>("opacity") { view: MarkerView, opacity ->
37
+ Prop<Float>("opacity") { view, opacity ->
33
38
  view.setOpacity(opacity)
34
39
  }
35
40
 
36
- Prop<Boolean>("flat") { view: MarkerView, flat ->
41
+ Prop<Boolean>("flat") { view, flat ->
37
42
  view.setFlat(flat)
38
43
  }
39
44
 
40
- Prop<Float>("zIndex") { view: MarkerView, zIndex ->
45
+ Prop<Float>("zIndex") { view, zIndex ->
41
46
  view.setZIndex(zIndex)
42
47
  }
43
48
 
44
- Prop<Map<String, Float>>("anchor") { view: MarkerView, anchor ->
49
+ Prop<Map<String, Float>>("anchor") { view, anchor ->
45
50
  view.setAnchor(anchor)
46
51
  }
47
52
 
48
- Prop<Int>("iconWidth") { view: MarkerView, width ->
53
+ Prop<Int>("iconWidth") { view, width ->
49
54
  view.setIconWidth(width)
50
55
  }
51
56
 
52
- Prop<Int>("iconHeight") { view: MarkerView, height ->
57
+ Prop<Int>("iconHeight") { view, height ->
53
58
  view.setIconHeight(height)
54
59
  }
55
60
 
56
- Prop<Int>("customViewWidth") { view: MarkerView, width ->
61
+ Prop<Int>("customViewWidth") { view, width ->
57
62
  view.setCustomViewWidth(width)
58
63
  }
59
64
 
60
- Prop<Int>("customViewHeight") { view: MarkerView, height ->
65
+ Prop<Int>("customViewHeight") { view, height ->
61
66
  view.setCustomViewHeight(height)
62
67
  }
63
68
  }
@@ -38,7 +38,7 @@ function MarkerDeclarative(props) {
38
38
  }
39
39
  };
40
40
  }, [eventManager, props.onPress, props.onDragStart, props.onDrag, props.onDragEnd]);
41
- return (<NativeMarkerView position={props.position} title={props.title} snippet={props.snippet} draggable={props.draggable} icon={props.icon} iconWidth={props.iconWidth || 0} // 传递原始的 iconWidth(用于自定义图标)
41
+ return (<NativeMarkerView latitude={props.position.latitude} longitude={props.position.longitude} title={props.title} snippet={props.snippet} draggable={props.draggable} icon={props.icon} iconWidth={props.iconWidth || 0} // 传递原始的 iconWidth(用于自定义图标)
42
42
  iconHeight={props.iconHeight || 0} // 传递原始的 iconHeight(用于自定义图标)
43
43
  customViewWidth={containerWidth} // 新增:自定义视图宽度
44
44
  customViewHeight={containerHeight} // 新增:自定义视图高度
@@ -1 +1 @@
1
- {"version":3,"file":"Marker.js","sourceRoot":"","sources":["../../../src/components/overlays/Marker.ts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ireNativeViewManager } from 'expo-modules-core';\nimport { MapContext, MarkerEventContext } from '../../ExpoGaodeMapView';\nimport type { MarkerProps } from '../../types';\n\nconst NativeMarkerView = requireNativeViewManager('MarkerView');\n\nexport default function Marker(props: MarkerProps) {\n // 如果有 children,使用声明式 API\n if (props.children) {\n return <MarkerDeclarative {...props} />;\n }\n // 否则使用命令式 API\n return <MarkerImperative {...props} />;\n}\n\nfunction MarkerDeclarative(props: MarkerProps) {\n const eventManager = React.useContext(MarkerEventContext);\n const markerIdRef = React.useRef(`marker_${Date.now()}_${Math.random()}`);\n \n // 根据是否有 children 来决定使用哪个尺寸属性\n // 有 children:使用 customViewWidth/customViewHeight(默认 80x30)\n // 无 children:使用 iconWidth/iconHeight(用于自定义图标)\n const containerWidth = props.children\n ? (props.customViewWidth && props.customViewWidth > 0 ? props.customViewWidth : 80)\n : (props.iconWidth || 0);\n const containerHeight = props.children\n ? (props.customViewHeight && props.customViewHeight > 0 ? props.customViewHeight : 30)\n : (props.iconHeight || 0);\n \n React.useEffect(() => {\n if (eventManager) {\n eventManager.register(markerIdRef.current, {\n onPress: props.onPress,\n onDragStart: props.onDragStart,\n onDrag: props.onDrag,\n onDragEnd: props.onDragEnd,\n });\n }\n return () => {\n if (eventManager) {\n eventManager.unregister(markerIdRef.current);\n }\n };\n }, [eventManager, props.onPress, props.onDragStart, props.onDrag, props.onDragEnd]);\n \n return (\n <NativeMarkerView\n position={props.position}\n title={props.title}\n snippet={props.snippet}\n draggable={props.draggable}\n icon={props.icon}\n iconWidth={props.iconWidth || 0} // 传递原始的 iconWidth(用于自定义图标)\n iconHeight={props.iconHeight || 0} // 传递原始的 iconHeight(用于自定义图标)\n customViewWidth={containerWidth} // 新增:自定义视图宽度\n customViewHeight={containerHeight} // 新增:自定义视图高度\n pinColor={props.pinColor}\n animatesDrop={props.animatesDrop}\n centerOffset={props.centerOffset}\n opacity={props.opacity}\n flat={props.flat}\n zIndex={props.zIndex}\n anchor={props.anchor}\n style={{ width: containerWidth, height: containerHeight }}\n >\n {props.children}\n </NativeMarkerView>\n );\n}\n\nfunction MarkerImperative(props: MarkerProps) {\n const mapRef = React.useContext(MapContext);\n const eventManager = React.useContext(MarkerEventContext);\n const markerIdRef = React.useRef<string | null>(null);\n const propsRef = React.useRef(props);\n \n React.useEffect(() => {\n propsRef.current = props;\n }, [props]);\n \n React.useEffect(() => {\n const checkAndAdd = () => {\n if (!mapRef?.current) {\n setTimeout(checkAndAdd, 50);\n return;\n }\n \n const markerId = `marker_${Date.now()}_${Math.random()}`;\n markerIdRef.current = markerId;\n \n if (eventManager) {\n eventManager.register(markerId, {\n onPress: props.onPress,\n onDragStart: props.onDragStart,\n onDrag: props.onDrag,\n onDragEnd: props.onDragEnd,\n });\n }\n \n const processedProps = { ...propsRef.current };\n if (processedProps.icon && typeof processedProps.icon === 'number') {\n const resolved = Image.resolveAssetSource(processedProps.icon);\n processedProps.icon = resolved;\n }\n \n mapRef.current.addMarker(markerId, processedProps);\n };\n \n checkAndAdd();\n \n return () => {\n if (markerIdRef.current) {\n if (eventManager) {\n eventManager.unregister(markerIdRef.current);\n }\n if (mapRef?.current) {\n mapRef.current.removeMarker(markerIdRef.current);\n }\n }\n };\n }, []);\n\n React.useEffect(() => {\n if (markerIdRef.current && eventManager) {\n eventManager.register(markerIdRef.current, {\n onPress: props.onPress,\n onDragStart: props.onDragStart,\n onDrag: props.onDrag,\n onDragEnd: props.onDragEnd,\n });\n }\n }, [eventManager, props.onPress, props.onDragStart, props.onDrag, props.onDragEnd]);\n\n React.useEffect(() => {\n if (markerIdRef.current && mapRef?.current) {\n const processedProps = { ...props };\n if (processedProps.icon && typeof processedProps.icon === 'number') {\n const resolved = Image.resolveAssetSource(processedProps.icon);\n processedProps.icon = resolved;\n }\n mapRef.current.updateMarker(markerIdRef.current, processedProps);\n }\n }, [\n mapRef,\n props.position?.latitude,\n props.position?.longitude,\n props.title,\n props.draggable,\n props.icon,\n props.iconWidth,\n props.iconHeight,\n props.customViewWidth,\n props.customViewHeight,\n props.pinColor\n ]);\n \n return null;\n}\n\n"]}
1
+ {"version":3,"file":"Marker.js","sourceRoot":"","sources":["../../../src/components/overlays/Marker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAGxE,MAAM,gBAAgB,GAAG,wBAAwB,CAAC,YAAY,CAAC,CAAC;AAEhE,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,KAAkB;IAC/C,yBAAyB;IACzB,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACnB,OAAO,CAAC,iBAAiB,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;IAC1C,CAAC;IACD,cAAc;IACd,OAAO,CAAC,gBAAgB,CAAC,IAAI,KAAK,CAAC,EAAG,CAAC;AACzC,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAkB;IAC3C,MAAM,YAAY,GAAG,KAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC1D,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAE1E,6BAA6B;IAC7B,2DAA2D;IAC3D,8CAA8C;IAC9C,MAAM,cAAc,GAAG,KAAK,CAAC,QAAQ;QACnC,CAAC,CAAC,CAAC,KAAK,CAAC,eAAe,IAAI,KAAK,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;QACnF,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC;IAC3B,MAAM,eAAe,GAAG,KAAK,CAAC,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,UAAU;QAChB,KAAK,CAAC,eAAe;QACrB,KAAK,CAAC,gBAAgB;QACtB,KAAK,CAAC,QAAQ;KACf,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import * as React from 'react';\nimport { Image } from 'react-native';\nimport { requireNativeViewManager } from 'expo-modules-core';\nimport { MapContext, MarkerEventContext } from '../../ExpoGaodeMapView';\nimport type { MarkerProps } from '../../types';\n\nconst NativeMarkerView = requireNativeViewManager('MarkerView');\n\nexport default function Marker(props: MarkerProps) {\n // 如果有 children,使用声明式 API\n if (props.children) {\n return <MarkerDeclarative {...props} />;\n }\n // 否则使用命令式 API\n return <MarkerImperative {...props} />;\n}\n\nfunction MarkerDeclarative(props: MarkerProps) {\n const eventManager = React.useContext(MarkerEventContext);\n const markerIdRef = React.useRef(`marker_${Date.now()}_${Math.random()}`);\n \n // 根据是否有 children 来决定使用哪个尺寸属性\n // 有 children:使用 customViewWidth/customViewHeight(默认 80x30)\n // 无 children:使用 iconWidth/iconHeight(用于自定义图标)\n const containerWidth = props.children\n ? (props.customViewWidth && props.customViewWidth > 0 ? props.customViewWidth : 80)\n : (props.iconWidth || 0);\n const containerHeight = props.children\n ? (props.customViewHeight && props.customViewHeight > 0 ? props.customViewHeight : 30)\n : (props.iconHeight || 0);\n \n React.useEffect(() => {\n if (eventManager) {\n eventManager.register(markerIdRef.current, {\n onPress: props.onPress,\n onDragStart: props.onDragStart,\n onDrag: props.onDrag,\n onDragEnd: props.onDragEnd,\n });\n }\n return () => {\n if (eventManager) {\n eventManager.unregister(markerIdRef.current);\n }\n };\n }, [eventManager, props.onPress, props.onDragStart, props.onDrag, props.onDragEnd]);\n \n return (\n <NativeMarkerView\n latitude={props.position.latitude}\n longitude={props.position.longitude}\n title={props.title}\n snippet={props.snippet}\n draggable={props.draggable}\n icon={props.icon}\n iconWidth={props.iconWidth || 0} // 传递原始的 iconWidth(用于自定义图标)\n iconHeight={props.iconHeight || 0} // 传递原始的 iconHeight(用于自定义图标)\n customViewWidth={containerWidth} // 新增:自定义视图宽度\n customViewHeight={containerHeight} // 新增:自定义视图高度\n pinColor={props.pinColor}\n animatesDrop={props.animatesDrop}\n centerOffset={props.centerOffset}\n opacity={props.opacity}\n flat={props.flat}\n zIndex={props.zIndex}\n anchor={props.anchor}\n style={{ width: containerWidth, height: containerHeight }}\n >\n {props.children}\n </NativeMarkerView>\n );\n}\n\nfunction MarkerImperative(props: MarkerProps) {\n const mapRef = React.useContext(MapContext);\n const eventManager = React.useContext(MarkerEventContext);\n const markerIdRef = React.useRef<string | null>(null);\n const propsRef = React.useRef(props);\n \n React.useEffect(() => {\n propsRef.current = props;\n }, [props]);\n \n React.useEffect(() => {\n const checkAndAdd = () => {\n if (!mapRef?.current) {\n setTimeout(checkAndAdd, 50);\n return;\n }\n \n const markerId = `marker_${Date.now()}_${Math.random()}`;\n markerIdRef.current = markerId;\n \n if (eventManager) {\n eventManager.register(markerId, {\n onPress: props.onPress,\n onDragStart: props.onDragStart,\n onDrag: props.onDrag,\n onDragEnd: props.onDragEnd,\n });\n }\n \n const processedProps = { ...propsRef.current };\n if (processedProps.icon && typeof processedProps.icon === 'number') {\n const resolved = Image.resolveAssetSource(processedProps.icon);\n processedProps.icon = resolved;\n }\n \n mapRef.current.addMarker(markerId, processedProps);\n };\n \n checkAndAdd();\n \n return () => {\n if (markerIdRef.current) {\n if (eventManager) {\n eventManager.unregister(markerIdRef.current);\n }\n if (mapRef?.current) {\n mapRef.current.removeMarker(markerIdRef.current);\n }\n }\n };\n }, []);\n\n React.useEffect(() => {\n if (markerIdRef.current && eventManager) {\n eventManager.register(markerIdRef.current, {\n onPress: props.onPress,\n onDragStart: props.onDragStart,\n onDrag: props.onDrag,\n onDragEnd: props.onDragEnd,\n });\n }\n }, [eventManager, props.onPress, props.onDragStart, props.onDrag, props.onDragEnd]);\n\n React.useEffect(() => {\n if (markerIdRef.current && mapRef?.current) {\n const processedProps = { ...props };\n if (processedProps.icon && typeof processedProps.icon === 'number') {\n const resolved = Image.resolveAssetSource(processedProps.icon);\n processedProps.icon = resolved;\n }\n mapRef.current.updateMarker(markerIdRef.current, processedProps);\n }\n }, [\n mapRef,\n props.position?.latitude,\n props.position?.longitude,\n props.title,\n props.draggable,\n props.icon,\n props.iconWidth,\n props.iconHeight,\n props.customViewWidth,\n props.customViewHeight,\n props.pinColor\n ]);\n \n return null;\n}\n\n"]}
@@ -20,6 +20,10 @@ class MarkerView: ExpoView {
20
20
 
21
21
  /// 标记点位置
22
22
  var position: [String: Double] = [:]
23
+ /// 临时存储的纬度
24
+ private var pendingLatitude: Double?
25
+ /// 临时存储的经度
26
+ private var pendingLongitude: Double?
23
27
  /// 标题
24
28
  var title: String = ""
25
29
  /// 描述
@@ -281,7 +285,49 @@ class MarkerView: ExpoView {
281
285
  }
282
286
 
283
287
  /**
284
- * 设置位置
288
+ * 设置纬度
289
+ */
290
+ func setLatitude(_ lat: Double) {
291
+ pendingLatitude = lat
292
+
293
+ // 如果经度也已设置,则更新位置
294
+ if let lng = pendingLongitude {
295
+ updatePosition(latitude: lat, longitude: lng)
296
+ }
297
+ }
298
+
299
+ /**
300
+ * 设置经度
301
+ */
302
+ func setLongitude(_ lng: Double) {
303
+ pendingLongitude = lng
304
+
305
+ // 如果纬度也已设置,则更新位置
306
+ if let lat = pendingLatitude {
307
+ updatePosition(latitude: lat, longitude: lng)
308
+ }
309
+ }
310
+
311
+ /**
312
+ * 更新标记位置(当经纬度都设置后)
313
+ */
314
+ private func updatePosition(latitude: Double, longitude: Double) {
315
+ let position = ["latitude": latitude, "longitude": longitude]
316
+
317
+ if mapView != nil {
318
+ // 地图已设置,直接更新
319
+ self.position = position
320
+ pendingLatitude = nil
321
+ pendingLongitude = nil
322
+ updateAnnotation()
323
+ } else {
324
+ // 地图还未设置,保存位置待后续应用
325
+ pendingPosition = position
326
+ }
327
+ }
328
+
329
+ /**
330
+ * 设置位置(兼容旧的 API)
285
331
  * @param position 位置坐标 {latitude, longitude}
286
332
  */
287
333
  func setPosition(_ position: [String: Double]) {
@@ -5,8 +5,13 @@ public class MarkerViewModule: Module {
5
5
  Name("MarkerView")
6
6
 
7
7
  View(MarkerView.self) {
8
- Prop("position") { (view: MarkerView, position: [String: Double]) in
9
- view.setPosition(position)
8
+ // 拆分 position 为两个独立属性以兼容 React Native 旧架构
9
+ Prop("latitude") { (view: MarkerView, lat: Double) in
10
+ view.setLatitude(lat)
11
+ }
12
+
13
+ Prop("longitude") { (view: MarkerView, lng: Double) in
14
+ view.setLongitude(lng)
10
15
  }
11
16
 
12
17
  Prop("title") { (view: MarkerView, title: String) in
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-gaode-map",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "description": "一个功能完整的高德地图 React Native 组件库,基于 Expo Modules 开发,提供地图显示、定位、覆盖物等功能。",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -47,7 +47,8 @@ function MarkerDeclarative(props: MarkerProps) {
47
47
 
48
48
  return (
49
49
  <NativeMarkerView
50
- position={props.position}
50
+ latitude={props.position.latitude}
51
+ longitude={props.position.longitude}
51
52
  title={props.title}
52
53
  snippet={props.snippet}
53
54
  draggable={props.draggable}