可以从python创建google地图吗?
我使用类似的代码获取地址的lat和long可以从python创建google地图吗?,python,google-maps,Python,Google Maps,我使用类似的代码获取地址的lat和long from pygeocoder import Geocoder for a in address: result = Geocoder.geocode(a) print(result[0].coordinates) 这很有效。有没有什么方法可以从python中实际生成包含这些点的GoogleMaps网页?如果能够尽可能地使用一种编程语言,那就太好了 我在网上搜索了很多解决方案,但没有找到任何合适的。也许这是不可能的?可以编写一个脚本
from pygeocoder import Geocoder
for a in address:
result = Geocoder.geocode(a)
print(result[0].coordinates)
这很有效。有没有什么方法可以从python中实际生成包含这些点的GoogleMaps网页?如果能够尽可能地使用一种编程语言,那就太好了
我在网上搜索了很多解决方案,但没有找到任何合适的。也许这是不可能的?可以编写一个脚本,将地理编码数据输出到KML文件中(很像HTML结构,但用于读取谷歌地图数据)。然后,您可以将KML文件上载到Google Maps上的“我的地图”,查看您收集的任何数据点,还有
您是否希望创建一个带有嵌入式Google地图的网页,该地图可以从Python中可视化这些数据?这将更加复杂(如果可能的话)。如果你想创建一个动态网页,你必须在某个时候生成一些Javascript代码,这使得KML不必要的开销。更容易生成生成正确映射的Javascript。这是一个很好的起点。它也有例子。下面是一个用于生成仅使用标记的代码的简单类:
from __future__ import print_function
class Map(object):
def __init__(self):
self._points = []
def add_point(self, coordinates):
self._points.append(coordinates)
def __str__(self):
centerLat = sum(( x[0] for x in self._points )) / len(self._points)
centerLon = sum(( x[1] for x in self._points )) / len(self._points)
markersCode = "\n".join(
[ """new google.maps.Marker({{
position: new google.maps.LatLng({lat}, {lon}),
map: map
}});""".format(lat=x[0], lon=x[1]) for x in self._points
])
return """
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<div id="map-canvas" style="height: 100%; width: 100%"></div>
<script type="text/javascript">
var map;
function show_map() {{
map = new google.maps.Map(document.getElementById("map-canvas"), {{
zoom: 8,
center: new google.maps.LatLng({centerLat}, {centerLon})
}});
{markersCode}
}}
google.maps.event.addDomListener(window, 'load', show_map);
</script>
""".format(centerLat=centerLat, centerLon=centerLon,
markersCode=markersCode)
if __name__ == "__main__":
map = Map()
# Add Beijing, you'll want to use your geocoded points here:
map.add_point((39.908715, 116.397389))
with open("output.html", "w") as out:
print(map, file=out)
from\uuuuu future\uuuuu导入打印功能
类映射(对象):
定义初始化(自):
self._点=[]
def添加点(自身、坐标):
self.\u points.append(坐标)
定义(自我):
centerLat=总和(x[0]表示x在自身点中))/len(自身点)
centerLon=总和(x[1]表示x个自成点))/len(自成点)
markersCode=“\n”。加入(
[“”“新建google.maps.Marker({{
位置:新的google.maps.LatLng({lat},{lon}),
地图:地图
}})“.”格式(lat=x[0],lon=x[1]),表示x在自身中
])
返回“”
var映射;
函数show_map(){{
map=new google.maps.map(document.getElementById(“地图画布”){{
缩放:8,
中心:新的google.maps.LatLng({centerLat},{centerLon})
}});
{markersCode}
}}
google.maps.event.addDomListener(窗口“加载”,显示地图);
“”格式(centerLat=centerLat,centerLon=centerLon,
markersCode=markersCode)
如果名称=“\uuuuu main\uuuuuuuu”:
map=map()
#加上北京,您将希望在此处使用地理编码点:
地图添加点((39.908715116.397389))
以open(“output.html”、“w”)作为输出:
打印(映射,文件=输出)
您可以使用gmplot库
它生成一个html文档,其中包含连接到GoogleMapsAPI的脚本。可以使用标记、散乱点、线、多边形和热图创建动态贴图
例如:
import gmplot
gmap = gmplot.GoogleMapPlotter(37.428, -122.145, 16)
gmap.plot(latitudes, longitudes, 'cornflowerblue', edge_width=10)
gmap.scatter(more_lats, more_lngs, '#3B0B39', size=40, marker=False)
gmap.scatter(marker_lats, marker_lngs, 'k', marker=True)
gmap.heatmap(heat_lats, heat_lngs)
gmap.draw("mymap.html")
谢谢。我真的只想做一个谷歌地图网页,然后我可以导航。我不需要从python思想中想象它。我有很多用python处理的数据,这些数据最终会给出位置。也许是正确的工具?一个复杂的问题是我想在地图上画阴影圈。也许这只能通过静态图像来完成?您还可以将KML上传到自己的服务器,并在地图上搜索URL。可能更简单。p、 谢谢你!我真的有zipcodes,我将在脚本的另一部分中单独定位它们。当然,除非谷歌有直接使用zipcodes的方法。其想法是你进行地理编码,然后将坐标传递给
地图。添加点
。现在如果你使用这段代码,你会看到一张带有“仅供开发之用”的地图,这可能会很烦人。如果你想要一个干净的地图,你应该按照说明启用你的账单,一旦你为谷歌地图启用了api密钥,你应该在脚本中添加&key=your\u api\u key
after=false