You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NativeScript-Vue Android使用@nativescript/google-maps添加标记报错:map.addMarker不是函数

解决NativeScript-Vue中@nativescript/google-maps的addMarker is not function错误

错误原因是你直接调用了MapView组件的addMarker方法,但这个方法属于组件内部的googleMap实例,而非组件本身。

修正后的代码:

onReady(event) {
    // 获取Google Maps的实际实例,而非MapView组件
    this.googleMap = event.map;
    this.addMarker(this.googleMap, this.markerOptions);
},

addMarker(map, markerOptions) {
    // 调用googleMap实例的addMarker方法
    const marker = map.addMarker(markerOptions);
    // 可选:自定义标记,比如设置图标
    // marker.icon = 'res://icon';
    return marker;
},

额外注意事项:

  • markerOptions必须包含position字段,需传入LatLng对象,示例:new mapsModule.LatLng(39.9042, 116.4074)
  • 确保已完成@nativescript/google-maps的依赖安装和平台配置(Android的API密钥、iOS的权限声明等)

内容的提问来源于stack exchange,提问作者ELGO ALLROF

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 06:04:52