简体   繁体   English

谷歌地图方向限制

[英]Google Maps directions limit

I have an app that opens routes created by other users.我有一个应用程序可以打开其他用户创建的路线。 In first essence, if a user does not have an app that supports.gpx files, the app will tell the user to simply get a supported app eg Strava.首先,如果用户没有支持 .gpx 文件的应用程序,该应用程序将告诉用户只需获取受支持的应用程序,例如 Strava。

But then it came to mind that perhaps I could merge the lattitudes and longtitudes in a Google Maps url.但后来我想到,也许我可以在Google Maps url 中合并纬度和经度。

String urlStart = "https://www.google.com/maps/dir/";
LocationParser locParser = new LocationParser();
List<LatLng> latLongList = await locParser.parseGPX(Uri.parse(route.file!));
latLongList.forEach((ltlng) {
  urlStart += '${ltlng.latitude.toStringAsFixed(3)},${ltlng.longitude.toStringAsFixed(3)}/';
});
Uri uri = Uri.parse(urlStart);
launchUrl(uri, mode: LaunchMode.externalApplication);

as you may expect this url becomes huge and the Google Maps app is not able to handle this input.正如您所预料的那样,这个 url 变得很大,而Google Maps应用程序无法处理此输入。 It is however able to handle the following url :但是它能够处理以下url

for (int i = 0; i < 50; i++) {
  var ltlng = latLongList[i];
  urlStart += '${ltlng.latitude.toString()},${ltlng.longitude.toString()}/';
}

Update更新

I figured the main issue is url-length.我认为主要问题是 url-length。 I only want to open Maps thus perhaps there is a way to send the directions directly to the app other than opening a maps url?我只想打开地图,因此除了打开地图 url 之外,也许还有一种方法可以将路线直接发送到应用程序? If not I have to have peace with the fact I cant do it如果不是,我必须坦然接受我做不到的事实

For example, some parameters use a pipe character (|) as a separator, which you must encode as %7C in the final URL. Other parameters use comma-separated values, such as latitude/longitude coordinates or City, State. You must encode the comma as %2C.例如,有些参数使用pipe字符(|)作为分隔符,您必须在最后的URL中编码为%7C。其他参数使用逗号分隔值,例如纬度/经度坐标或城市,State。您必须编码逗号为 %2C。 Encode spaces with %20, or replace them with a plus sign (+).使用 %20 对空格进行编码,或将其替换为加号 (+)。

Additionally, URLs are limited to 2,048 characters for each request.此外,每个请求的 URL 限制为 2,048 个字符。 Be aware of this limit when constructing your URLs.构建 URL 时请注意此限制。

SOURCE: Constructing valid URLs来源: 构建有效的 URL

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

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