使用ajax python在google地图上绘制坐标

使用ajax python在google地图上绘制坐标,python,html,ajax,button,Python,Html,Ajax,Button,我试图在谷歌地图上绘制从我创建的网络服务中绘制的坐标,并根据您在单击“提交”按钮后输入的内容标记位置。然而,我被困在如何让提交按钮触发函数这样做 (store_coords.csv包含“ID”“Name”“Lat”“Lon”列)。 布里斯班,10,20 要在地图上绘制它,我会搜索getlocation/1,它会在地图上的10,20处放置一个标记 我的web服务代码是: import petl as etl from bottle import run, get locations = etl.

我试图在谷歌地图上绘制从我创建的网络服务中绘制的坐标,并根据您在单击“提交”按钮后输入的内容标记位置。然而,我被困在如何让提交按钮触发函数这样做

(store_coords.csv包含“ID”“Name”“Lat”“Lon”列)。 布里斯班,10,20

要在地图上绘制它,我会搜索getlocation/1,它会在地图上的10,20处放置一个标记 我的web服务代码是:

import petl as etl
from bottle import run, get

locations = etl.fromcsv("store_coords.csv").dicts()
loc_list = []
for l in locations:
loc_list.append(l)

@get('/getlocation/<id>')
def getOne(id):
   the_location = [location for location in locations if location['ID'] == id]
   return {'location': the_location}

run(reloader=True, debug=True)
将petl作为etl导入
从瓶子导入运行,获取
locations=etl.fromcsv(“store_coords.csv”).dicts()
loc_列表=[]
对于位于以下位置的l:
附件(l)
@获取('/getlocation/'))
def getOne(id):
_location=[location for location in location if location['ID']==ID]
返回{'location':位置}
运行(重新加载程序=True,调试=True)
我的html代码:

<!DOCTYPE html>
<html lang="en">
<html>
  <head>
    <title>Simple Map</title>
    <meta name="viewport" content="initial-scale=1.0">
    <meta charset="utf-8">
    <style>
      html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
      #map {
        height: 100%;
      }
    </style>
  </head>
  <body>
  Please enter location ID: <input type="text" name="ID" placeholder="e.g             getlocation/1" autofocus required="required"/>
        <br>
<button id="submit">Locate on Google Maps</button>
        <br>
    <div id="map"></div>
    <script>
$(document).ready(function(){
   $("#submit").click(function(){
      $.ajax( {
         url: "http://localhost:8080/getlocation/" + $("#store_id").val(),
         method: "get",
         dataType: "json"
      })
        .done( function(msg) {
            var result = msg.locations;
            for ( var i = 0; i < result.length; i++ ) {
                result[i].placeName;
                result[i].lat;
                result[i].lng;
            }
        });
    marker = new google.maps.Marker({
    map: map,
    position: {lat: locations.lat, lng: locations.lng},
    title: {location: locations.placeName}
  });
 });
});
var map;
function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
  center: {lat: -26.715, lng: 153.064},
  zoom: 12
});


map.setCenter(marker.getPosition());
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?
key=AIzaSyCO3hE4bE7WV7mGuXL4kn9caoWI44tD8Ic&callback=initMap" async defer> 
</script>
</body>
</html>

简单地图
html,正文{
身高:100%;
保证金:0;
填充:0;
}
#地图{
身高:100%;
}
请输入位置ID:

在谷歌地图上找到
$(文档).ready(函数(){ $(“#提交”)。单击(函数(){ $.ajax({ url:“http://localhost:8080/getlocation/“+$(“#存储id”).val(), 方法:“获取”, 数据类型:“json” }) .done(函数(msg){ var结果=消息位置; 对于(变量i=0;i

我觉得我的“marker=…”代码走错了方向。任何反馈都很好,谢谢

当您尝试运行它时会发生什么?怎么了?你的Javascript看起来很奇怪。如果你收到一个坐标数组,你可能应该在for循环中创建你的标记?我有一个文本框和页面顶部的提交按钮,还有一个空白的谷歌地图。当我尝试搜索例如getlocation/1(尝试从csv中的id 1绘制co ord值)时,什么都没有发生。当您尝试运行它时会发生什么?怎么了?你的Javascript看起来很奇怪。如果你收到一个坐标数组,你可能应该在for循环中创建你的标记?我有一个文本框和页面顶部的提交按钮,还有一个空白的谷歌地图。当我尝试搜索例如getlocation/1(尝试从csv中的id 1绘制co ord值)时,什么都没有发生。