【问题标题】:Can I use AngularJS with Static Google Maps?我可以将 AngularJS 与静态谷歌地图一起使用吗?
【发布时间】:2015-04-07 20:41:43
【问题描述】:

https://maps.googleapis.com/maps/api/staticmap?size=440x420&scale=2&style=feature:all|element:labels|visibility:off&markers=color:green|size:small|90,-180

所以我有类似上面显示的链接。该链接不太有效,我所做的只是将其缩短为 1 个坐标并使用可能不正确的坐标。

但是,你应该明白了。我是否可以改为这样做:

<div id="mapWrap" ng-controller="EdwardMap">
  <img src="https://maps.googleapis.com/maps/api/staticmap?size=440x420&scale=2&style=feature:all|element:labels|visibility:off&markers=color:green|size:small|{{building.mapcoord}}" usemap="#Map">

我已经尝试过了,但我无法让它工作。我下面还有其他代码使用相同的控制器并且工作正常,但我希望 Angular 可以帮助我生成图像!如果你认为我的图片链接有问题,我正在使用的那个可以正常工作,它只是有更多的坐标和其他好东西。我拿了其中一个并用{{building.mapcoords}}替换它。

这是building.mapcoords 的来源:

$scope.building = [{
        name:"name2",
        mapcoords:"80,-170",
        address:"address2",
        htmlcoords:"556,69,565,72,568,75,568,85,564,92,559,100,557,108,554,98,550,92,546,86,546,76,552,69",
    },{
        name:"name1",
        mapcoords:"",
        address:"address1",
        htmlcoords:"699,270,708,274,710,277,710,285,707,291,702,300,699,308,696,300,693,292,689,287,688,276,694,271"
    }

谢谢!

【问题讨论】:

  • 不工作时怎么办?您是否检查了网络选项卡以查看用于请求图像的路径?你没有给我们太多的合作..
  • 另外,你应该使用 ng-src,这样你就不会在 angular 解析它之前向 api 发送 badrequest。
  • 打开网络选项卡并查看请求的图像 url。是你所期望的吗?
  • 我显然忽略了这是否可能,通常这个问题的答案是肯定的,以某种方式
  • 构建实际上是一个数组,所以,是的,你必须像数组一样使用它。建筑[0].mapcoords

标签: angularjs google-static-maps


【解决方案1】:

尝试使用ngSrc 应该可以正常工作,因为您对 url 发出另一个请求,将其视为一个资源,一个不同的图像

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-18
    • 1970-01-01
    • 2014-04-16
    • 2014-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多