[英]NATIVESCRIPT + JS add marker to map with button
how can i select mymap by id and then add the marker ?如何通过 id 选择 mymap 然后添加标记?
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:这是我的 xml 页面:
<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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.