admin管理员组文章数量:1317915
I created and event listener to perform a function when the user drag a marker but it's not working, could anyone help me ?
This is the event listener
google.maps.event.addListener(marker, 'dragend', enviarParaASP(marker));
And the function:
function enviarParaASP(marcador) {
coordenadaASalvar = { latitude: marcador.position.d, longitude: marcador.position.e };
jQuery.ajax({
url: 'GoogleMapsGeolocation.aspx/SalvaCoordenadas',
type: "POST",
data: JSON.stringify({'coord': coordenadaASalvar}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) { alert("OK "); },
failure: function (msg) { alert("Sorry!!! "); }
});
I created and event listener to perform a function when the user drag a marker but it's not working, could anyone help me ?
This is the event listener
google.maps.event.addListener(marker, 'dragend', enviarParaASP(marker));
And the function:
function enviarParaASP(marcador) {
coordenadaASalvar = { latitude: marcador.position.d, longitude: marcador.position.e };
jQuery.ajax({
url: 'GoogleMapsGeolocation.aspx/SalvaCoordenadas',
type: "POST",
data: JSON.stringify({'coord': coordenadaASalvar}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) { alert("OK "); },
failure: function (msg) { alert("Sorry!!! "); }
});
Share
Improve this question
edited Jul 6, 2019 at 8:25
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Mar 5, 2014 at 0:59
LuccasMFLuccasMF
4335 silver badges15 bronze badges
2 Answers
Reset to default 6Your syntax is incorrect:
google.maps.event.addListener(marker, 'dragend', enviarParaASP(marker));
will run your function and assign the return value as the listener function (not what you want, particularly since the function doesn't have a return value, so it will be null).
The line should be:
google.maps.event.addListener(marker, 'dragend', enviarParaASP);
And enviarParaASP should take a google.maps.MouseEvent as its argument.
Your callback should just be a reference to your function, not an invocation:
google.maps.event.addListener(marker, 'dragend', enviarParaASP);
By invoking the function, it's only going to "fire" when it appears in your code, which is when you're trying to set up the listener.
本文标签: javascriptEvent on marker drag Google Maps API V3Stack Overflow
版权声明:本文标题:javascript - Event on marker drag Google Maps API V3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742024076a2415214.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论