temp.js 2.3 KB
requestUrl = "http://api.visitkorea.or.kr/openapi/service/rest/KorService/locationBasedList?serviceKey=D0l3YlPyS%2FkOOP6THiiZfSx2sqFsFLD7F14cAj7kqio3k7G%2BPHsb66v2W4C5qOuj7GeEXqjaYsFFZcn%2BLIDItg%3D%3D&numOfRoews=10&startPage=1&MobileOS=ETC&MobileApp=openSource&arrange=A&contenTypeId=15&listYN=Y&radius=10000"
requestNumUrl = "http://api.visitkorea.or.kr/openapi/service/rest/KorService/locationBasedList?serviceKey=D0l3YlPyS%2FkOOP6THiiZfSx2sqFsFLD7F14cAj7kqio3k7G%2BPHsb66v2W4C5qOuj7GeEXqjaYsFFZcn%2BLIDItg%3D%3D&numOfRoews=10&MobileOS=ETC&MobileApp=AppTest&arrange=A&contenTypeId=15&radius=10000&listYN=N"

resultObject = new Array();

function findShops(latitude, longitude) {

  //var parameter = "&mapX=" + 126.981611 + "&mapY=" + 37.568477;
  pageIndex = 1;
  var parameter = "&mapX=" + longitude + "&mapY=" + latitude + "&pageNo=" + pageIndex;
  $.ajax({
     type: "GET"
     ,dataType: "xml"
     ,url: requestUrl + parameter
     ,success: function(xml){
        totalCount = Number($(xml).find("totalCount").text());
        for(pageIndex=1; pageIndex<=totalCount/10; pageIndex++)
        {
          $.ajax({
             type: "GET"
             ,dataType: "xml"
             ,url: requestUrl + "&mapX=" + longitude + "&mapY=" + latitude + "&pageNo=" + pageIndex
             ,success: function(xml){
                  var xmlData = $(xml).find("items item");
                  var listLength = xmlData.length;
                  if (listLength) {
                      $(xmlData).each(function(){
                        var data = new Object() ;
                        data.title = $(this).find("title").text()
                        data.lng = $(this).find("mapx").text()
                        data.lat = $(this).find("mapy").text()
                        //console.log(data)
                        resultObject.push(data);
                      });

                      var markers = resultObject.map(function(currentValue, index, array) {
                        var marker = new google.maps.Marker({
                          position: {lat: Number(currentValue.lat), lng: Number(currentValue.lng)},
                          title: currentValue.title,
                        });
                        marker.setMap(map);
                      });
                  }
              }
           });
        }
      }
   });
}