首页 文章

NativeScript动态 Map 标记

提问于
浏览
0

如何在我的 Map 中添加动态标记?
例如 ..

<ListView items="{{ myItems }}" itemTap="mapClicked">

当我单击我的列表视图项时,应动态地向 Map 添加标记 . 我尝试了许多不同的方法但没有成功 .
我试过这个回购:https://github.com/dapriett/nativescript-google-maps-sdk
它工作正常..但我无法动态添加标记 .

有什么帮助吗?

1 回答

  • 3

    要使用 nativescript-google-maps-sdk 添加标记,您需要为相应平台的Google Maps SDK调用本机API .

    以下是Android的示例:

    function onMapReady(args) {
      mapView = args.object;
    
    }
    
    function mapClicked(args)
    {
       var index = args.index;
       var gMap = mapView.gMap;
    
       if (mapView.android)
       {
        var latLng = new com.google.android.gms.maps.model.LatLng(12.66, 82.33);
    
        var markerOptions = new com.google.android.gms.maps.model.MarkerOptions();
        markerOptions.title("Marker " + index);      
        markerOptions.snippet("Marker description");
        markerOptions.position(latLng);
    
        gMap.addMarker(markerOptions);           
    
       }
    }
    

相关问题