首页 > 解决方案 > 允许使用 REST API 创建和修改数据的位置服务

问题描述

我想知道是否有可以创建/更新/删除数据的 REST API。例如,我想做的是在地图上创建一个图钉或通过 REST API 保存我在地图上找到的最喜欢的地方。

谷歌地图之前有这个功能,但从这篇文章中被弃用:https ://cloud.google.com/blog/products/maps-platform/announcing-deprecation-of-place-add

我正在通过 Google Maps API 并看不到这个选项,我也检查过 HERE maps API 但它似乎没有提供这个。

是否有任何 API 可以做到这一点,基本上发送 POST/PUT/DELETE 请求以检查地图/位置服务的工作方式?

标签: pythonrestgoogle-mapshere-api

解决方案


您可以直接使用Fleet Telematics Custom Locations REST api,也可以使用HERE maps for JavaScript API与此 REST api 进行通信。

第二种选择是使用非常易于使用的HERE studio 。

以下是如何使用 HERE maps for JavaScript API 上传点几何图形(标记)的简单示例:

// assuming there is already H.Map (map) & H.service.Platform (platform) instance

const layerId = 'MY_LAYER';
const cleService = platform.getCustomLocationService();

// check if layer in fleet telematics custom location service exists.
// if yes, upload data. 
// If not create new layer, then upload data
cleService.getLayer(layerId, uploadData, createLayer);

/*
 * this method creates marker with random position and uploads it to the server
 */
function uploadData(table) {
  let row = table.addRow(),
      bearing = Math.random() * 360,
      distance = Math.random() * 3000,
      // marker with random position in radius 3km from map's center
      marker = new H.map.Marker(map.getCenter().walk(bearing, distance));

  // add marker to the map
  map.addObject(marker);

  row.setCell('NAME', 'Test name'); // optional
  row.setCell('WKT', marker.getGeometry()); // mandatory

  // push the marker's geometry to the fleet telematics custom location service
  cleService.appendRows([row], () => {console.log('O.K.')}, console.log);
}

/*
 * this method creates new layer in fleet telematics custom location service
 */
function createLayer() {
  // only WKT is mandatory column name
  let metaInfo = {
    layerId,
    columnNames: ['NAME', 'GEOMETRY_ID', 'WKT']
  };

  cleService.createLayer(metaInfo, uploadData, console.error);
}

这是一个简单的示例,如何使用 HERE maps for JavaScript API 在地图上显示上传的点几何图形:

// assuming there is already H.Map (map) & H.service.Platform (platform) instance

const layerId = 'MY_LAYER';
const cleService = platform.getCustomLocationService();

// Create a tile layer:
cleLayer = cleService.createTileLayer({layerId}, {
  resultType: H.service.extension.TileProvider.ResultType.MARKER
});

// Add the tile layer to the map
map.addLayer(cleLayer); // uploaded geometries start to show from zoom 12

推荐阅读