传单地图网址被禁止 [英] Leaflet map url is forbidden

查看:50
本文介绍了传单地图网址被禁止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 jquery mobile phonegap 应用程序,并且我想使用嵌入其中的传单地图.我目前正在做一个非常基本的概念验证,但我运气不佳.每次我尝试加载地图时,地图的 .png 都不会加载,控制台会告诉我它是禁止的.我想我可能设置了错误的地图 URL,但 CloudMade 网站上的文档有点模糊.您能提供的任何帮助将不胜感激.

I'm trying to create a jquery mobile phonegap app and I want to use leaflet maps embedded in it. I'm doing a pretty basic proof-of-concept at the moment, but I'm not having much luck. Every time I try to load the map, the .png of the map doesn't load and the console tells me its Forbidden. I think I'm probably setting up the map URL wrong, but the documentation is a little fuzzy on the CloudMade website. Any help you can provide would be greatly appreciated.

代码:

var map = new L.Map('map');

var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/MY_APP_KEY/997/256/{z}/{x}/{y}.png',
    cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18});
map.addLayer(cloudmade);

map.locateAndSetView(16);

map.on('locationfound', onLocationFound);

function onLocationFound(e) {
    var radius = e.accuracy / 2;

    var marker = new L.Marker(e.latlng);
    map.addLayer(marker);
    marker.bindPopup("You are within " + radius + " meters from this point").openPopup();

    var circle = new L.Circle(e.latlng, radius);
    map.addLayer(circle);
}

map.on('locationerror', onLocationError);

function onLocationError(e) {
    alert(e.message);
}

当我尝试加载图像时,出现以下错误:GET http://a.tile.cloudmade.com/MY_APP_KEY/997/256/0/0/0.png 403(禁止).显然,我正在用我从 CloudMade 获得的密钥替换 MY_APP_KEY,但除此之外,我不知道还能去哪里.

When I try to load the image, I get the following error: GET http://a.tile.cloudmade.com/MY_APP_KEY/997/256/0/0/0.png 403 (Forbidden). Obviously I'm replacing MY_APP_KEY with my key that I got from CloudMade, but other than that, I'm not sure where else to turn.

预先感谢您的帮助.

推荐答案

提供 Cloudmade API 密钥是强制性的,但还不够.您还必须提供一个令牌,您必须为每个用户和设备请求该令牌.如 Cloudmade Authorization API doc 中所述,可以通过简单的 POST 检索令牌:

Providing the Cloudmade API key is mandatory but not sufficient. You also have to provide a token that you will have to request for each user and device. As described in Cloudmade Authorization API doc the token can be retrieved by a simple POST :

POST http://auth.cloudmade.com/token/APIKEY?userid=UserID&deviceid=DeviceID

这将为您提供一个令牌,您必须将其附加到磁贴 url 以在 cloudmade 服务器上进行身份验证:

This will give you a token that you have to append to the tiles url to authenticate on cloudmade servers :

var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/MY_APP_KEY/997/256/{z}/{x}/{y}.png?token=TOKEN'

然而,为了快速验证概念,您可以直接使用他们自己的 API 密钥,不需要身份验证令牌:

For a quick proof of concept however, you can directly use their own API key which do not need authentication token :

var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/8ee2a50541944fb9bcedded5165f09d9/997/256/{z}/{x}/{y].png

这篇关于传单地图网址被禁止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆