Google Maps API的使用


.png)

.png)
.png)
.png)

.png)

.png)
.png)
.png)
import googlemaps
from datetime import datetime gmaps = googlemaps.Client(key='Add Your Key here') # Geocoding an address
geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')
print(geocode_result[0]['geometry']['location']) # Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((40.714224, -73.961452))
print(reverse_geocode_result[0]['address_components'][1]['long_name'])

.png)
import googlemaps
from datetime import datetime gmaps = googlemaps.Client(key='Add Your Key here')
# Request directions via public transit
now = datetime.now()
directions_result = gmaps.directions("Sydney Town Hall",
"Parramatta, NSW",
mode="transit",
departure_time=now)
print(directions_result)
import googlemaps
from datetime import datetime
import os
import csv
import pandas as pd
import matplotlib.pyplot as plt
import math # 将已知的多个txt文件中的内容放到一个CSV文件下
def txt2Csv(dataPath, csvname):
fileList = os.listdir(dataPath)
csvFile = open(dataPath + '\\' + csvname, 'w+')
writer = csv.writer(csvFile)
for fileName in fileList:
with open(dataPath + '\\' + fileName) as fileObj:
lines = fileObj.readlines()
for line in lines:
line = line.split(',')
line[-1] = line[-1][0:-1]
writer.writerow((line))
csvFile.close() # 根据经纬度获取两地之间的距离及花费的时间
def getDistanceDuration(key, path, csvName):
gmaps = googlemaps.Client(key=key)
df = pd.read_csv(path + '\\' + csvName)
df.columns = ['id', 'time', 'longitude', 'latitude']
durationList = []
distanceList = []
try:
for i in range(1, 1000):
now = datetime.now()
# 调取google API的directions:
directions_result = gmaps.directions((df.iloc[i, 3], df.iloc[i, 2]),
(df.iloc[i+1, 3], df.iloc[i+1, 2]),
mode="driving",
departure_time=now)
# 按照返回的格式,找出distance及duration,追加到列表中并返回
distanceList.append(directions_result[0]['legs'][0]['distance']['value'])
durationList.append(directions_result[0]['legs'][0]['duration']['value'])
except googlemaps.exceptions._RetriableRequest:
pass
return distanceList, durationList path = 'D:\\Learnning\\python\\scrape\\taxiData\\T-drive Taxi Trajectories\\release\\taxi_log_2008_by_id'
txt2Csv(path, 'geodata.csv') distanceList, durationList = getDistanceDuration('AIzaSyD8X6tJx6Ap5TVHlqwSso8iTwZfDWcFsOA', path, 'geodata.csv')
# 对返回数据的单位做转换, 并使用math.ceil对数据向上取整
distanceList = [math.ceil(dis/1000) for dis in distanceList]
durationList = [math.ceil(dis/60) for dis in durationList] totalDistance = 0
totalDuration = 0
# 计算总路程,并画出每段路程的距离在总路程中的占比:
for distance in distanceList:
totalDistance += distance
distancePropo = [distance/totalDistance for distance in distanceList]
plt.bar(distanceList, distancePropo)
plt.title("Distance interval")
plt.xlabel("Km")
plt.ylabel("Proportion")
plt.show() # 计算总时间,并画出每段路程花费的时间在总时间中的占比:
for duration in durationList:
totalDuration += duration
durationPropo = [duration/totalDuration for duration in durationList]
plt.bar(durationList, durationPropo)
plt.title("Time interval")
plt.xlabel("Min")
plt.ylabel("Proportion")
plt.show()
.png)
按行驶距离分布:

具体的使用文档可参考:Google Maps API的使用的更多相关文章
- Google Maps API V3 之绘图库 信息窗口
		
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
 - Google Maps API V3 之 图层
		
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
 - Google Maps API V3 之 路线服务
		
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
 - google maps  api申请的问题
		
现在已经改由统一的GOOGLE API控制台进行所有GOOGLE API的管理了. 方法是使用Google帐号登入 https://code.google.com/apis/console. 然后在所 ...
 - Google maps API开发(一)(转)
		
一.加载Google maps API <script type="text/javascript" src="http://ditu.google.com/map ...
 - Google maps API开发(二)(转)
		
这一篇主要实现怎么调用Google maps API中的地址解析核心类GClientGeocoder: 主要功能包括地址解析.反向解析.本地搜索.周边搜索等, 我这里主要有两个实例: 实例一.当你搜索 ...
 - Google Maps API Web Services
		
原文:Google Maps API Web Services 摘自:https://developers.google.com/maps/documentation/webservices/ Goo ...
 - Google maps API开发
		
原文:Google maps API开发 Google maps API开发(一) 最近做一个小东西用到google map,突击了一下,收获不小,把自己学习的一些小例子记录下来吧 一.加载Googl ...
 - Google Maps API Key申请办法(最新)
		
之前的Google Maps Api的API Key很容易申请,只需要按照一个简单的表单提交部署的网站地址即可,自动生成API Key并给出引用的路径. 但是最近在处理另外一个项目的时候发现之前的这种 ...
 - 如何插入谷歌地图并获取javascript api 秘钥--Google Maps API error: MissingKeyMapError
		
参考:https://blog.csdn.net/klsstt/article/details/51744866 Google Maps API error: MissingKeyMapError h ...
 
随机推荐
- iterator的romove方法的注意事项
			
package cn.lonecloud.Iterator; import java.util.ArrayList; import java.util.Iterator; public class m ...
 - 通过js区分移动端浏览器(微信浏览器、QQ浏览器、QQ内置浏览器)
			
由于公司业务中涉及到一个分享指引功能,而像微信.QQ内置浏览器需要引导用户点击右上角进行操作,其他浏览器则引导点击浏览器下方进行操作,因此需要区分浏览器类型: 通过在页面alert(navigator ...
 - 关于UIButton嵌入到UIView点击无反应问题的解决方法和delegate的简单用法示例(转载)
			
做项目封装UIView的时候碰到的问题,没想到有个哥们儿还写成博客,特此收藏! 问题是这样的,几个界面用到同一个自定义返回按钮,于是就想着把这个按钮单独封装起来,添加一个UIView类,在里面自定义U ...
 - python开发concurent.furtrue模块:concurent.furtrue的多进程与多线程&协程
			
一,concurent.furtrue进程池和线程池 1.1 concurent.furtrue 开启进程,多进程&线程,多线程 # concurrent.futures创建并行的任务 # 进 ...
 - 通讯服务类API调用的代码示例合集:短信服务、手机号归属地查询、电信基站查询等
			
以下示例代码适用于 www.apishop.net 网站下的API,使用本文提及的接口调用代码示例前,您需要先申请相应的API服务. 短信服务:通知类和验证码短信,全国三网合一通道,5秒内到达,费用低 ...
 - hashtable的运用实例
			
#include <hash_set> #include <iostream> using namespace std; int main() { hashtable<i ...
 - zTree实现地市县三级级联Service接口测试
			
zTree实现地市县三级级联Service接口测试 ProvinceServiceTest.java: /** * @Title:ProvinceServiceTest.java * @Package ...
 - g++基本用法
			
用法:g++[选项]文件... g++编译流程: main.cxx #include <iostream> using namespace std; int main(void) { co ...
 - dtls_srtp学习笔记
			
注:以下为rfc5764的学习笔记,不保证完全正确. DTLS-SRTP是DTLS的一个扩展,将SRTP加解密与DTLS的key交换和会话管理相结合.从SRTP的角度看,是为其提供一种新的key协商管 ...
 - CSS开启硬件加速提高网站性能
			
国外一篇文章,有点意思,转载过来,准备尝试下~ 中文地址:http://www.cnblogs.com/yzw7489757/ 原文地址:http://blog.teamtreehouse.com/i ...