【问题标题】:How to correctly submit POST positioning request via HERE API from a local environment?如何从本地环境通过 HERE API 正确提交 POST 定位请求?
【发布时间】:2020-08-19 11:56:48
【问题描述】:

我使用 XAMPP 堆栈在 Windows 10 上进行本地开发。

http://localhost:8003/myFolder/

这是我的代码:

Code snippet: URL without CORS mechanism

我收到以下错误: 发布https://pos.ls.hereapi.com/positioning/v1/locate?apiKey=Lxj-xbibfpSHLMw1U...blabla net::ERR_ABORTED 400(错误请求)

Code snippet: URL with CORS mechanism

我收到以下错误: POST http://host/path?CORSH=%7B%22Content-Type%22%3A%22application%2Fvnd.here.layerObjectList%2Bjson%3B%20charset%3Dutf-8%22%2C%22Accept%22%3A% 22application%2Fjson%3B%20charset%3DUTF-8%22%2C%22GroupId%22%3A%22FGx1AWaAzKOo0imNkLmf%22%2C%22AuthServiceId%22%3A%22here_app%22%2C%22Auth-Identifier%22%3A%22Ykv6MmZ03OJtiFD4R7Ht% 22%2C%22Auth-Secret%22%3A%22AXqUNIsVW46XJs9_pxuzOzneKlYPrY5X_blablabla net::ERR_NAME_NOT_RESOLVED

【问题讨论】:

    标签: json geolocation maps here-api geopositioning


    【解决方案1】:

    我也有同样的问题:

    url = 'https://geocode.search.hereapi.com/v1/geocode?q=Eichholz 27 ,+ 20459 ,+ Hamburg ,+ D&apiKey=yYoMr6vEReqc_sI0HAPMqIu3fYJdGcRsBR5t-xxxxxx' ;

    $.ajax({ 跨域:是的, 类型:'得到', 标头:{“访问控制允许来源”:“*”}, 网址:网址, contentType: "应用程序/json; charset=utf-8", 数据类型:'json', jsonCallback : 'getJson', 异步:假, 成功:函数(数据){ $.each(data, function(counter, daten) {

                alert('return -- ' + daten.titel) ;
            });
        },
        error : function(data, req, status, err) {
            alert('something went wrong !!! getLatLng(url)');
            // console.log('something went wrong', status, err);
    
        }
    }); // ajax end
    

    Quellübergreifende (Cross-Origin) Anfrage blockiert: Die Gleiche-Quelle-Regel verbietet das Lesen der externen Ressource auf https://geocode.search.hereapi.com/v1/geocode?q=Winterfeldtstrasse%2079,+%2010781%20,+%20Berlin%20,+%20GERMANY&apiKey=yYoMr6vEReqc_sI0HAPMqIu3fYJdGcRsBR5t-xxxxx。 (基础:CORS-Anschlag schlug fehl)

    【讨论】:

      【解决方案2】:

      原则上,AJAX 不支持外部 URL。 如果一定要调用aURL Like

      url = 'https://geocode.search.hereapi.com/v1/geocode?q=Eichholz 27 ,+ 20459 ,+ Hamburg ,+ D&apiKey=yYoMr6vEReqc_sI0HAPMqIu3fYJdGcRsBR5t-xxxxxx' ;

      您必须使用 $.getJSON 来完成。 喜欢:

         function getLatLng(url, location_id) {
      
      $.getJSON(url, function(data) {
          $.each(data, function(counter, daten) {
              // alert(url);
              JSON.stringify(daten);
              // alert('return -- ' + counter + '-- ' + daten.title ) ;
      
              function print_r(printthis, returnoutput) {
                  var output = '';
      
                  if ($.isArray(printthis) || typeof (printthis) == 'object') {
                      for ( var i in printthis) {
                          output += i + ' : ' + print_r(printthis[i], true)
                                  + '\n';
                          // alert('for - ' + printthis[i]);
                      }
                  } else {
                      output += printthis;
                      // alert('else - ' + printthis + '--' + printthis[i]);
                  }
      
                  if (returnoutput && returnoutput == true) {
                      return output;
                  } else {
                      // alert(output);
                      var nlat = output.indexOf("lat : ", 10);
                      // alert(nlat);
                      var lat = output.substring((nlat + 6), ((nlat + 6) + 9));
      
                      var nlng = output.indexOf("lng : ", 10);
                      var lng = output.substring((nlng + 6), ((nlng + 6) + 9));
          alert('location_id - ' + location_id + '  lat ' + lat + '  lng ' + lng);
                      updateAdress(lat, lng, location_id , todo)
                  }
      
              }
      
              print_r(daten);
              // console.dir(daten);
          });     }); }
      

      【讨论】:

        猜你喜欢
        • 2018-11-26
        • 2017-12-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-07
        • 2017-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多