获取通用winJS项目中的请求

时间:2015-12-29 10:59:52

标签: javascript google-maps google-maps-api-3 win-universal-app winjs

我有地图和其他网络服务,我想要的是在地图中显示标记 根据Web服务的信息,这是我的代码:

map.html:

<head>
    <!-- USGS URL data source -->
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>
    <script src="/week.js"></script>
    <!-- Google Maps API reference -->
    <script
        src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=visualization">
    </script>
    <!-- mapframe references -->
    <link href="/map.css" rel="stylesheet" />
    <script src="/map.js"></script>
</head>
<body>
        <div id="mapdisplay"></div>
</body>

week.js,我在其中调用Web服务:

$.ajax({
    url: "URL",
    type: "GET",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (results, textStatus, xhr) {
        console.log(results.stringify);
    },
    error: function (error) { alert('ERROR has occurred!'); alert(JSON.stringify(error)) }
});

和map.js将每个局部放在地图中:

var dataa;
var map;

function initialize() {
    map = new google.maps.Map(document.getElementById('mapdisplay'), {
        zoom: 15,
        center: new google.maps.LatLng(35.840041,10.624909),
        mapTypeId: google.maps.MapTypeId.TERRAIN
    });
    eqfeed_callback(results);
    addMarkers();
}

eqfeed_callback = function (results) {
    dataa = results;
}


function addMarkers() {

    for (var i = 0; i < dataa.locals.length; i++) {
        //var quake = dataResults[i];
        //var coors = quake.geometry.coordinates;
        var latLong = new google.maps.LatLng(dataa.locals[i].local_longi, dataa.locals[i].local_latit);
        var marker = new google.maps.Marker({
            position: latLong,
            map: map,
            icon: './images/BB_mapIcon.png'
        });

    }

}

function getCircle(magnitude) {
    return {
        path: google.maps.SymbolPath.CIRCLE,
        fillColor: 'red',
        fillOpacity: .2,
        scale: Math.pow(2, magnitude) / Math.PI,
        strokeColor: 'white',
        strokeWeight: .5
    };
}

google.maps.event.addDomListener(window, 'load', initialize);

我得到一个例外,无法获得&#34;长度&#34; null引用的属性或未定义 想念我的代码中的任何东西 如何更正我的代码,从week.js中的Web服务获取数据并将其显示在map.js中 谢谢你的帮助

我在一个通用的WinJS项目上工作,这是我想要提取lattitude / langitude值的json数据:

{
success: 1,
message: "local found",
total: 1,
locals: [
  {
  id_local: "1",
  local_longi: "14.6996",
  local_latit: "588.39",
  }
]
}

0 个答案:

没有答案