我知道当您的请求包含超过 25 个出发地或超过 25 个目的地时,会显示“MAX_DIMENSIONS_EXCEEDED”错误。但我只是想知道这个限制仅适用于免费 api 客户还是适用于所有人?
我正在使用以下谷歌服务
var service = new google.maps.DistanceMatrixService();
我正在使用 Google 的 Java 距离矩阵 API。我有正常工作的代码,但我希望它返回两个纬度经度点(出发地、目的地)之间的距离(以公里为单位)。但没有这样的方法或参数可以返回 kms 距离。但是,如果距离值大于或等于 1km,则返回以 km 为单位的距离。但我希望它始终以公里为单位返回距离(例如0.5公里) ,但当距离小于 1 km 时,它总是以米为单位返回距离。我也尝试使用Unit.METRIC,但它没有用,因为它仍然仅返回以米为单位的距离。
DistanceMatrix results = DistanceMatrixApi.getDistanceMatrix(context,
new String[] {origins}, new String[] {destinations}).units(Unit.METRIC).await();
results.rows[0].elements[0].distance //returns in meters, i want it in kms.
Run Code Online (Sandbox Code Playgroud) 根据文档,我们以下列方式检索一组源和目标之间的距离(服务器API).
https://maps.googleapis.com/maps/api/distancematrix/json?origins=Washington%20DC&destinations=New%20York&mode=walking&key=
Run Code Online (Sandbox Code Playgroud)
如果我们将place_id作为原点或目的地传递,那么最好不要传递地名.这样可以得到更准确的结果.可能吗 ?
例如.是否可以执行API调用,如:
https://maps.googleapis.com/maps/api/distancematrix/json?origins=<place_id>&destinations=<place_id>&mode=walking&key=
Run Code Online (Sandbox Code Playgroud)
???
谢谢
我是一个自制的开发人员,我不知道该怎么做。我正在尝试使用android设置程序,用户将在其中键入Textviews:出发城市,到达城市,出发日期和出发时间。然后,该应用程序将显示两个城市之间的距离,行程时间,到达日期和到达时间。
我在搜索时发现了一些工具,但我不知道如何使用它们。谁能帮我。我已经被困了几个星期了:-(?
我想计算两点之间的持续时间。我知道有 Google Maps API,但我不想使用它,我需要一个方程式来完成它。有一种方法可以计算我在行驶时间内需要的距离。
java android google-maps-android-api-2 google-distancematrix-api
我正在编写一个应用程序,可以在路线中计算两个位置。我已经实现了谷歌地点 API 以根据名称或地址获取纬度/经度,但我无法实现距离 API。当我尝试导入时,类/方法不会出现。下面是我正在尝试做的一个例子。
private static final String API_KEY = "YOUR_API_KEY";
private static final GeoApiContext context = new
GeoApiContext().setApiKey(API_KEY);
public DistanceMatrix estimateRouteTime(DateTime time, Boolean isForCalculateArrivalTime, DirectionsApi.RouteRestriction routeRestriction, LatLng departure, LatLng... arrivals) {
try {
DistanceMatrixApiRequest req = DistanceMatrixApi.newRequest(context);
if (isForCalculateArrivalTime) {
req.departureTime(time);
} else {
req.arrivalTime(time);
}
if (routeRestriction == null) {
routeRestriction = DirectionsApi.RouteRestriction.TOLLS;
}
DistanceMatrix trix = req.origins(departure)
.destinations(arrivals)
.mode(TravelMode.DRIVING)
.avoid(routeRestriction)
.language("fr-FR")
.await();
return trix;
} catch (ApiException e) {
System.out.println(e.getMessage());
} catch (Exception e) {
System.out.println(e.getMessage());
} …Run Code Online (Sandbox Code Playgroud) 所以我开发了一个代码,我在其中读取包含一些位置的文件(更准确地说是 15 个),其中第一个是仓库,其他 14 个位置是公共汽车需要经过以收集患者的地方。为了做到这一点,我使用 Google Maps API 密钥来收集真实距离并将它们最终写入 .txt 文件中。
import pandas as pd
import googlemaps
from itertools import tee
import numpy as np
#Read CSV file into data frame named 'df'
#change seperator (sep e.g. ',') type if necessary
df = pd.read_csv("D:/Utilizadores/Documents/FEUP/2018-2019/1º Semestre/PDI/Relatório/locais2.txt", sep='\\t',
engine='python', skiprows=[0], names=["address", "latitude", "longitude"])
lat = np.expand_dims(np.array(df["latitude"]), 1)
lon = np.expand_dims(np.array(df["longitude"]), 1)
coordinates = np.concatenate((lat, lon), axis=1)
coordinates = list(coordinates)
coordinates = [list(coor) for coor in coordinates]
#Perform request to use the Google …Run Code Online (Sandbox Code Playgroud) 我不是很流利的Javascript,但我正在尝试使用它来构建一个简单的Web应用程序来尝试学习更多.
我想使用Google Distance Matrix API让我查询两个地址之间的距离.
我有两个输入字段,使用Google的自动完成功能来获取地址,然后我使用place_id地址来查询API.
我相信我需要使用JSONP来调用API并获取数据,但是我在使用响应时遇到问题,并且在控制台中出现以下错误:
未捕获的SyntaxError:意外的令牌:
我一直在寻找,每个人都在使用PHP和JSONP - 但是我想要避免这种情况并保持整个进程的客户端.
如何发出请求然后使用返回的JSON响应?
这是我目前用来发出请求的函数:
function getDistance()
{
//Find the distance
$.getJSON("https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=place_id:" + $("#autocompleteDeparture").data("place_id") + "&destinations=place_id:" + $("#autocompleteArrival").data("place_id") + "&key=MY_API_KEY0&callback=?", function(data) {
data = JSON.parse(data);
console.log(data);
});
}
Run Code Online (Sandbox Code Playgroud)
如果我检查请求,它正在成功运行并返回正确的JSON数据:
{
"destination_addresses" : [ "9 Coach Ln, Belmont, Lower Hutt 5010, New Zealand" ],
"origin_addresses" : [ "3/30 Rata St, Naenae, Lower Hutt 5011, New Zealand" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "4.9 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Google Maps API 计算两个地点之间的预计旅行时间。我通过以下方式索取数据:
\n\nconst Url = \'https://maps.googleapis.com/maps/api/distancematrix/json?origins=25.7694708,-80.259947&destinations=25.768915,-80.254659&key=\' + API_KEY;\ntry {\n const response = await fetch(Url);\n console.log(response);\n const data = await response.json();\n console.log(data.rows);\n} catch(e){\n console.log(e);\n}\nRun Code Online (Sandbox Code Playgroud)\n\n问题是在浏览器控制台中我收到错误:
\n\nTypeError: NetworkError when attempting to fetch resource\nRun Code Online (Sandbox Code Playgroud)\n\n它还向我显示了一个警告:
\n\nCross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://maps.googleapis.com/maps/api/distancematrix/json?origins=25.7694708,-80.259947&destinations=25.768915,-80.254659&key=API_KEY. (Reason: CORS header \xe2\x80\x98Access-Control-Allow-Origin\xe2\x80\x99 missing).\nRun Code Online (Sandbox Code Playgroud)\n\n但是当我查看网络部分的控制台时,它显示调用已成功完成,并且显示以下 json:
\n\n{\n "destination_addresses" : [ "3670 SW 3rd St, Miami, FL 33135, USA" ],\n "origin_addresses" : [ "3911 …Run Code Online (Sandbox Code Playgroud) google-maps ×5
java ×3
android ×2
javascript ×2
api ×1
fetch-api ×1
jquery ×1
json ×1
reactjs ×1