python - 允许使用 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 请求以检查地图/位置服务的工作方式?
解决方案
您可以直接使用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
推荐阅读
- laravel - 如何使“上传文件”不是必需的 - Laravel 8
- security - Apiman 2.0.0 安全漏洞
- javascript - 为什么我无法在外部点击时使用 react js 访问我的两个容器的当前目标值?
- apache-kafka - AppendStreamTableSink 不支持消费由节点 Join(joinType=[InnerJoin]
- excel - 使用表格公式将数字舍入到上限值
- android - Android - 如何在默认浏览器中打开 PWA 外部链接,而不是在同一个应用程序中?
- node.js - 如何处理express中的redis连接错误?
- angular - document.title 是否优于 Angular Title 服务?
- mongodb - 无法在 Ubuntu 20.04.2 LTS 上启动 mongod 进程
- java - Vaadin 参考RouterLayout中的mainLayout