可拖动,在Google AppMaker上 [英] Draggable, on Google AppMaker

查看:94
本文介绍了可拖动,在Google AppMaker上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些指导,因为我还没有找到我需要的解释.

I want a little guidance, because I haven't found the explanation I need yet.

我正在Google App Maker上开发网站,并且想在Google Map Widget上使用可拖动标记.

I'm developing a website on Google App Maker, and I want to use on Google Map Widget a Draggable Marker.

我找到的所有信息都类似于外部网站,包括HTML和JavaScript库.输入以下内容时显示错误:

All the info I have found, is like for an external website including HTML and JavaScript libraries. The error is shown when I type:

var marker = new google.maps.Marker({
  position: latlon,
  map: map,
  draggable: true,
  title:"Drag me!"
});

未捕获的TypeError:google.maps.Marker不是构造函数 在var marker = new google.maps.Marker({(NewScript1:143).

"Uncaught TypeError: google.maps.Marker is not a constructor at var marker = new google.maps.Marker ({ (NewScript1: 143) ".

我尝试过使用客户端脚本和服务器端脚本.

I have tried in client side script, and in server side script.

问题,如果我想使用标记,我需要向appmaker添加库吗?

Question, if I want to use a marker I need to add libraries to appmaker?

推荐答案

最有可能出现此错误,因为在加载Maps API之前正在执行客户端脚本.要100%确保已加载该代码,您需要在Google Map Widget的onAttach事件中执行代码(也许onDataLoad也会起作用).

Most likely you are getting the error because you are executing your client script before Maps API is loaded. To be 100% sure that it is loaded you need to execute your code in onAttach event of the Google Map Widget (maybe onDataLoad one will work as well).

如果要使App Maker默认将其添加到地图的Marker可以拖动,则可以使用以下代码段:

If you want to make the Marker that App Maker adds to the map by default draggable you can use this snippet:

// Google Map widget's onAttach event handler
var marker = widget.getAddressMarkerJs();
marker.setDraggable(true);

如果您要添加全新的标记,可以使用以下代码段:

In case you want to add all-new marker(s) you can use this snippet:

// Google Map widget's onAttach event handler
var map = widget.getMapJs();

var marker = new google.maps.Marker({
  position: { lat: 0, lng: 0 },
  map: map,
  draggable: true,
  title:"Drag me!"
});

奖金代码段可从地图中删除默认标记

Bonus snippet to remove default marker from the map

// Google Map widget's onAttach event handler
var marker = widget.getAddressMarkerJs();
marker.setMap(null);

这篇关于可拖动,在Google AppMaker上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆