确定随机坐标(纬度,经度)是否在特定路线上
Determine whether a random coordinate (latitude, longitude) is on the particular route
我正在使用 IONIC/CORDOVA 开发跨平台应用程序。如何确定半径为 50 米的随机坐标(纬度、经度)是否在特定路线上?
假设我定义了一条从一个区域到另一个区域的路线。我需要找出我的应用程序在该特定路线上的用户。
执行此任务的最佳方法是什么? Google 地图 API 还是 OpenStreetMap?
此致
阿希库尔·拉赫曼
我会用 Google Maps Geocoding API.
示例:
var xhr = new XMLHttpRequest(),
route = "E261", // route name
latlng = "52.3547673,16.8840211"; // lat and lng
xhr.open("GET", "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + latlng, true);
xhr.addEventListener("load", function() {
var response = JSON.parse(xhr.response).results;
response.forEach(function(result) {
if (result.types.indexOf("route") !== -1 && result.formatted_address.indexOf(route) !== -1)
console.log("route found");
});
});
xhr.addEventListener("error", function() {
// handle error
});
xhr.send();
我正在使用 IONIC/CORDOVA 开发跨平台应用程序。如何确定半径为 50 米的随机坐标(纬度、经度)是否在特定路线上?
假设我定义了一条从一个区域到另一个区域的路线。我需要找出我的应用程序在该特定路线上的用户。
执行此任务的最佳方法是什么? Google 地图 API 还是 OpenStreetMap?
此致
阿希库尔·拉赫曼
我会用 Google Maps Geocoding API.
示例:
var xhr = new XMLHttpRequest(),
route = "E261", // route name
latlng = "52.3547673,16.8840211"; // lat and lng
xhr.open("GET", "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + latlng, true);
xhr.addEventListener("load", function() {
var response = JSON.parse(xhr.response).results;
response.forEach(function(result) {
if (result.types.indexOf("route") !== -1 && result.formatted_address.indexOf(route) !== -1)
console.log("route found");
});
});
xhr.addEventListener("error", function() {
// handle error
});
xhr.send();