Javascript Ionic使用Bing地图代理失败,访问控制允许源问题
我目前正在开发我的第一个混合应用程序,我对CORS有一个问题。Bing MAP API不允许本地主机或实际设备调用其Rest API。我试着用两种不同的方式联系Bing 第一次尝试是使用我的服务中的url和config.xml中列出的所有url,但我找到了并出错 第二个是代理url,这是一个查询url。我不知道如何代理一个查询url,所以我一直在使用一个重新格式化的测试url,但这会得到一个404 有人知道我如何解决我的CORS问题吗?先谢谢你 “方法1`Javascript Ionic使用Bing地图代理失败,访问控制允许源问题,javascript,proxy,ionic-framework,gulp,bing-maps,Javascript,Proxy,Ionic Framework,Gulp,Bing Maps,我目前正在开发我的第一个混合应用程序,我对CORS有一个问题。Bing MAP API不允许本地主机或实际设备调用其Rest API。我试着用两种不同的方式联系Bing 第一次尝试是使用我的服务中的url和config.xml中列出的所有url,但我找到了并出错 第二个是代理url,这是一个查询url。我不知道如何代理一个查询url,所以我一直在使用一个重新格式化的测试url,但这会得到一个404 有人知道我如何解决我的CORS问题吗?先谢谢你 “方法1` service.js functi
service.js
function getUserAddress() {
var uriQuery = http://dev.virtualearth.net/REST/v1/Locations/point?point=40.444009, -77.774055&includeEntityTypes=Address,Neighborhood,CountryRegion&includeNeighborhood=1&output=json&key=(removed);
return $http({
method: 'GET',
url: uriQuery,
}).then(function (response) {
console.log("location data set", response);
return getNearbyEvents(response);
}).catch(rxEventsService.onRequestFailure);
}
// webserver: Create local webserver with livereload.
gulp.task('webserver', function () {
gulp.src('./www')
.pipe(webserver({
fallback: './www/index.html',
host: '0.0.0.0',
port: 8080,
proxies: [{
source: '/_bingmaps',
target: 'http://dev.virtualearth.net/REST/v1/Locations/point?point=40.444009, -77.774055&includeEntityTypes=Address,Neighborhood,CountryRegion&includeNeighborhood=1&output=json&key=(removed)'
}]
}));
});
function getUserAddress() {
return $http({
method: 'GET',
url: rxUrls.reverseGeoCoding,
}).then(function (response) {
console.log("location data set", response);
return getNearbyEvents(response);
}).catch(rxEventsService.onRequestFailure);
}
Config.xml
<access origin="*"/>
<allow-navigation href="*"/>
constants.js
(function () {
'use strict';
angular.module('rxEvents').constant('rxUrls', {
reverseGeoCoding:'/_bingmaps',
bingMapsKey:'(removed)'
});
})();
service.js
function getUserAddress() {
var uriQuery = http://dev.virtualearth.net/REST/v1/Locations/point?point=40.444009, -77.774055&includeEntityTypes=Address,Neighborhood,CountryRegion&includeNeighborhood=1&output=json&key=(removed);
return $http({
method: 'GET',
url: uriQuery,
}).then(function (response) {
console.log("location data set", response);
return getNearbyEvents(response);
}).catch(rxEventsService.onRequestFailure);
}
// webserver: Create local webserver with livereload.
gulp.task('webserver', function () {
gulp.src('./www')
.pipe(webserver({
fallback: './www/index.html',
host: '0.0.0.0',
port: 8080,
proxies: [{
source: '/_bingmaps',
target: 'http://dev.virtualearth.net/REST/v1/Locations/point?point=40.444009, -77.774055&includeEntityTypes=Address,Neighborhood,CountryRegion&includeNeighborhood=1&output=json&key=(removed)'
}]
}));
});
function getUserAddress() {
return $http({
method: 'GET',
url: rxUrls.reverseGeoCoding,
}).then(function (response) {
console.log("location data set", response);
return getNearbyEvents(response);
}).catch(rxEventsService.onRequestFailure);
}
错误
ionic.bundle.min.js:135 POST 404(未找到)Bing地图REST服务是支持JSONP的服务。下面是一篇博客文章,解释如何使用各种JavaScript框架访问此服务: