我对slaple非常陌生,我正在尝试如何将slaple中的onmaclick事件中的lat和lng返回到flask服务器应用程序,以便使用坐标在我的数据库中执行空间搜索。事件当前只在web应用程序的弹出窗口中显示lat long。在
我已经搜索过了,但我想我的知识太基础了,我不知道我在搜索什么函数。在
我的网络地图
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" /> <!-- Leaflet CSS file (style sheets)>-->
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script> <!--leaflet java script file>-->
</head>
<body>
<div id="map1" style="width: 800px; height: 600px;"></div>
<script>
var mymap = L.map('map1').setView([51.5, -0.09], 10);
<!--add map to display>-->
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
maxZoom: 18,
id: 'mapbox.streets',
accessToken: '*****************'
}).addTo(mymap);
<!--add popups as a layer>-->
var popup = L.popup();
<!--logs the action and gives lat long of where click occured >-->
function onMapClick(e) {
.setLatLng(e.latlng)
.setContent("You clicked the map at " + e.latlng.toString())
.openOn(mymap);
}
mymap.on('click', onMapClick);
</script>
</body>
</html>
以及服务器应用程序
^{pr2}$编辑
我试图使用ajax调用,但得到了405错误
$.ajax('demo/data/', {
type: 'GET',
data: {
lat: e.latlng.lat,
lng: e.latlng.lng
}
});
};
烧瓶应用程序
@app.route('/demo/data/')
def demoData():
return request.form['lng'], request.form['lat']
405错误是
method not allowed
错误。 在使用restapi时,应该使用POST
请求发送信息,如here所述。在你要改变你的应用程序路径到
允许post方法
相关问题 更多 >
编程相关推荐