0

我想通过从 mapbox 调用 API 来获取静态图像,但它返回了这条消息:

{"message":"Failed parsing geojson"} // with status code:422

我使用 mapbox_search 包来创建 API。这是我的代码:

MapBoxStaticImage staticImage = MapBoxStaticImage(
apiKey:
    'pk.eyJ1IjoiYXNocmFmaWowMDciLCJhIjoiY2s2Nm40ZjFkMDAxMDNubXo3M3V4Y2pvaiJ9.cQACwGfCXD1iuKdJeZDozA',
);

Future<String> getStaticImageWithMarker() async {
final locationData = await locationFinder.Location().getLocation();
return staticImage.getStaticUrlWithMarker(
  center: Location(lat: locationData.latitude, lng: locationData.longitude),
  marker: MapBoxMarker(
      markerColor: Color.rgb(200, 0, 0),
      markerLetter: 'p',
      markerSize: MarkerSize.LARGE),
  height: 300,
  width: 600,
  zoomLevel: 16,
  style: MapBoxStyle.Streets,
  render2x: true,
);
}

getStaticImageWithMarker() 函数返回此 api 用于创建图像,但我得到了我在顶部提到的错误。

https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/pin-l-p+c800(-122.084,37.4219983)/-122.084,37.4219983,16,0,20/600x300@2x?access_token=pk.eyJ1IjoiYXNocmFmaWowMDciLCJhIjoiY2s2Nm40ZjFkMDAxMDNubXo3M3V4Y2pvaiJ9.cQACwGfCXD1iuKdJeZDozA

有没有人知道我在这个 APIcalling 中做错了什么?

4

3 回答 3

2

在 mapbox 中,我收到“无效图像”错误。我在 Mapbox 样式中选择 Carto,它已修复。

在此处输入图像描述

于 2021-04-23T12:15:43.070 回答
0

我创建了一个获取经度和纬度的函数,并从 mapbox 返回图像的链接:

String getStaticImageWithMarker(double latitude, double longitude) {
return 'https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/' +
    'geojson(%7B%22type%22%3A%22Point%22%2C%22coordinates%22%3A%5B$longitude%2C$latitude%5D%7D)/$longitude,$latitude,16/500x300?' +
    'access_token=your token from mapbox';
}

之后,您可以使用网络上的图像框来获取地点图像。

于 2021-01-14T09:28:18.137 回答
0

这就是 MapBox 解释如何使用 Jafar 在他的回答中描述的对我有用的链接的地方。

https://docs.mapbox.com/api/maps/static-images/

文档中的示例:

/styles/v1/{username}/{style_id}/static/{overlay}/{lon},{lat},{zoom},{bearing},{pitch}|{bbox}|{auto}/{width} x{高度}{@2x}

返回链接后,在 Image.network 小部件中使用它,如下所示:

Image.network('${getStaticImageWithMarker(routeLat, routeLong)}'),

于 2021-01-23T09:05:33.947 回答