简体   繁体   中英

NATIVESCRIPT + JS add marker to map with button

how can i select mymap by id and then add the marker ?

function addMarker(args){
        var MyMapById; // i dont know how to bind mymaps to this variable
        MyMapById.clear();
        var marker = new mapsModule.Marker();
        marker.position = mapsModule.Position.positionFromLatLng(latitude, longitude);
        MyMapById.addMarker(marker);
    }

here is my xml page:

<Page 
    xmlns="http://www.nativescript.org/tns.xsd"
    xmlns:maps="nativescript-google-maps-sdk"
    navigatedTo="onNavigatedTo">
    <GridLayout rows="auto, *">
        <Button text="Add Marker" tap="addMarker" />

        <maps:mapView latitude="{{ latitude }}" longitude="{{ longitude }}" row="1" id="mymap"  
         mapAnimations="false" cameraChanged="onCameraChanged" zoom="12" mapReady="onMapReady" />
    </GridLayout>
</Page>

thanks.

您必须能够使用 getViewById 方法获取对页面上任何组件的引用,例如page.getViewById("mymap")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM