简体   繁体   English

Google Maps JavaScript API 的 Google Maps Distance Matrix 语言规范

[英]Google Maps Distance Matrix Language specification for Google Maps JavaScript API

i want a script to calculate distance between 2 points.我想要一个脚本来计算两点之间的距离。

The problem is, i need the json output to be in my language (Greek).问题是,我需要 json 输出是我的语言(希腊语)。

If i use this url: https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&language=el&origins=TILEFOU%2019%20PATRA%20ACHAIA&destinations=leonidou%2019%20patra如果我使用这个网址: https : //maps.googleapis.com/maps/api/distancematrix/json? units = metric & language = el & origins = TILEFOU%2019%20PATRA%20ACHAIA & destinations = leonidou%2019% 20patra

the address returns to me in greek no matter how i enter it.无论我如何输入,该地址都会以希腊语返回给我。

But if i use the js script i dont know how to set the language i prefer.但是如果我使用 js 脚本,我不知道如何设置我喜欢的语言。

This is the script provided by Google:这是谷歌提供的脚本:

function calculateDistance(origin, destination) {
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
  origins: [origin],
  destinations: [destination],
  travelMode: google.maps.TravelMode.DRIVING,
  unitSystem: google.maps.UnitSystem.METRIC,
  avoidHighways: false,
  avoidTolls: false
}, callback);

} }

But i cant find any param for language, is there any trick or id have to create a script to use with the json url ?但是我找不到任何语言参数,是否有任何技巧或 id 必须创建一个脚本来与 json url 一起使用?

Thank you.谢谢你。

I don't have a workaround other than what you suggested, using the Distance Matrix API web service (remember that the API should be invoked from the server side, so you should wrap it in your own service).除了您建议的方法外,我没有其他解决方法,即使用距离矩阵 API Web 服务(请记住,应从服务器端调用 API,因此您应该将其包装在您自己的服务中)。 It seems like language should be a parameter, so I created a public issue tracker which you can find here:语言似乎应该是一个参数,所以我创建了一个公共问题跟踪器,你可以在这里找到:

https://code.google.com/p/gmaps-api-issues/issues/detail?id=11484&thanks=11484&ts=1487381207 https://code.google.com/p/gmaps-api-issues/issues/detail?id=11484&thanks=11484&ts=1487381207

You can set a language when you load Maps JavaScript API in your page.您可以在页面中加载 Maps JavaScript API 时设置语言。 It will be set globally for all further client side requests.它将为所有进一步的客户端请求全局设置。 Have a look at the documentation:看看文档:

https://developers.google.com/maps/documentation/javascript/localization#Language https://developers.google.com/maps/documentation/javascript/localization#Language

However, indeed there is no way to specify a language different from the one set in a bootstrap in client side service requests.然而,确实没有办法指定一种不同于客户端服务请求中引导程序中设置的语言。 Hopefully, Rob's feature request will be implemented in the future.希望 Rob 的功能请求将在未来实现。

Please star the feature request in the public issue tracker to add your vote and receive updates from Google.请在公共问题跟踪器中为功能请求加注星标,以添加您的投票并接收来自 Google 的更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM