【问题标题】:Use google.maps in Azure Mobile Service NodeJS在 Azure 移动服务 NodeJS 中使用 google.maps
【发布时间】:2016-09-30 14:51:39
【问题描述】:

我正在使用 Azure 移动服务 - NodeJS 后端 我想检查多边形地图是否包含一个点。 怎么用google地图库就可以了?还是没办法?

--谢谢--

    var customerLatLng = new google.maps.LatLng(lat, lng);
    var area = serviceParsed[0];
    /*example: [{"type":"POLYGON","id":null,"geometry":[[[21.070767653166016,105.80863952636719],[21.01180841534327,105.77705383300781],[21.031036817912042,105.87455749511719]]]}] */
    var triangleCoords = [];
    if (area.type == "POLYGON") {
      for (var j = 0; j < area.geometry[0].length; j++) {
        triangleCoords.push({
          "lat": area.geometry[0][j][0],
          "lng": area.geometry[0][j][1]
        });
      };
    } else { }
    var bermudaTriangle = new google.maps.Polygon({ paths: triangleCoords });
    if (google.maps.geometry.poly.containsLocation(customerLatLng, bermudaTriangle)) {
      filteredResults.push(item.Id);
    }

【问题讨论】:

  • 只是为了验证,您想在 Node 后端使用 Google Maps SDK?在什么情况下?你能发布一个完整的样本吗?
  • 是的,就像上面的例子,我想使用谷歌地图来检查一个多边形区域是否包含移动服务 API(Node JS)中的一个点(位置)。但我收到错误“未定义谷歌”
  • 确认一下,您使用的是 Azure 移动服务还是 Azure 移动应用?
  • @Gary Liu - MSFT:我正在使用 Azure 移动服务
  • 你安装了azure.microsoft.com/en-us/documentation/articles/…提到的模块吗?

标签: node.js google-maps azure azure-mobile-services


【解决方案1】:

我对 Azure 移动服务进行了更多研究。我们可以将其他 nodejs 模块安装到移动服务的 package.json 中。 所以,这是步骤:

  1. 为移动服务设置源代码控制(例如:GIT)
  2. 将 API 代码克隆到客户端文件夹(使用 SourceTree)
  3. 安装模块需要用到
  4. 将 package.json 提交到服务器

例如: 1. npm 安装 geolib 2. 步骤3后的package.json文件

"engines": {
    "node": ">= 0.8.19"
  },
  "dependencies": {
    "geolib": "^2.0.21",
    "point-in-polygon": "^1.0.1"
  },
  1. 提交 package.json

  2. 在 api 文件中:

    var geolib= 必需(“geolib”); // 使用https://www.npmjs.com/package/geolib

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    • 1970-01-01
    • 1970-01-01
    • 2016-04-10
    • 2012-12-11
    相关资源
    最近更新 更多