2012-09-24 2 views
0

Foursquare에는 API 사용법에 대한 몇 가지 예가 나와 있습니다. 하지만 내 주요 질문은 어떻게 추출하고 인근 인기있는 장소의지도에 포인트보다는 목록을 표시 할 수 있습니까? Foursquare에서 데이터를 추출하여 나열하는 위치

https://developer.foursquare.com/overview/tutorial

나는이 아주 새로운 해요 및 방법이나 언어 (JSON, JQuery와, 등)를 사용 해야할지 모르겠어.

누구든지 방향을 찾거나 Foursquare, https://developer.foursquare.com/docs/venues/trending을 통해 만들 수있는 URL에서 데이터를 가져 와서 나열하는 방법을 시작하는 데 도움이됩니까?

여기에 그들이 전화를지도에 표시하기 위해 사용하는 코드입니다,하지만 난 목록을 원합니다 :

<?xml version="1.0" encoding="UTF-8"?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html> 
<head> 
    <title>foursquare :: Explore Sample</title> 

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript" id="jquery"></script> 


    <link href="/styles/leaflet.css" type="text/css" rel="stylesheet" /> 
    <link href="/styles/apisamples.css" type="text/css" rel="stylesheet" /> 

    <script src="/scripts/apisamples.js" type="text/javascript"></script> 
    <script src="/scripts/third_party/jquery.ba-bbq.js" type="text/javascript"></script> 
    <script src="/scripts/third_party/leaflet.js" type="text/javascript"></script> 
    <script src="/scripts/third_party/wax.leaf.min.js" type="text/javascript"></script> 

    <style type="text/css"> 
    html { height: 100%; } 
    body { height: 100%; margin: 0; padding: 0; } 
    /* Give our markers a background image */ 
    .leaflet-marker-icon { 
     background: url(https://foursquare.com/img/pin-blue-transparent.png); 
     padding: 6px; 
     padding-bottom: 17px; 
     top: -6px; 
     left: -6px; 
     } 
    </style> 

    <script type="text/javascript"> 

    var config = { 
    apiKey: 'XXXXXXXXXXXXXX', 
    authUrl: 'https://foursquare.com/', 
    apiUrl: 'https://api.foursquare.com/' 
    }; 


    //<![CDATA[ 

    /* Attempt to retrieve access token from URL. */ 
    function doAuthRedirect() { 
    var redirect = window.location.href.replace(window.location.hash, ''); 
    var url = config.authUrl + 'oauth2/authenticate?response_type=token&client_id=' + config.apiKey + 
     '&redirect_uri=' + encodeURIComponent(redirect) + 
     '&state=' + encodeURIComponent($.bbq.getState('req') || 'users/self'); 
    window.location.href = url; 
    }; 

    if ($.bbq.getState('access_token')) { 
    // If there is a token in the state, consume it 
    var token = $.bbq.getState('access_token'); 
    $.bbq.pushState({}, 2) 
    } else if ($.bbq.getState('error')) { 
    } else { 
    doAuthRedirect(); 
    } 

    /* HTML 5 geolocation. */ 
    navigator.geolocation.getCurrentPosition(function(data) { 
    var lat = data['coords']['latitude']; 
    var lng = data['coords']['longitude']; 
    /* Create map. */ 
    var map = new L.Map('map_canvas') 
     .setView(new L.LatLng(lat, lng), 15); 
    /** 
    * This is a sample map url that you need to change. 
    * Sign up at http://mapbox.com/foursquare for a custom map url. 
    */ 
    var mapboxUrl = 'http://a.tiles.mapbox.com/v3/foursquare.map-b7qq4a62.jsonp'; 
    wax.tilejson(mapboxUrl, function(tilejson) { 
     map.addLayer(new wax.leaf.connector(tilejson)); 
    }); 

    /* Query foursquare API for venue recommendations near the current location. */ 
    $.getJSON(config.apiUrl + 'v2/venues/explore?ll=' + lat + ',' + lng + '&oauth_token=' + window.token, {}, function(data) { 
     venues = data['response']['groups'][0]['items']; 
     /* Place marker for each venue. */ 
     for (var i = 0; i < venues.length; i++) { 
     /* Get marker's location */ 
     var latLng = new L.LatLng(
      venues[i]['venue']['location']['lat'], 
      venues[i]['venue']['location']['lng'] 
     ); 
     /* Build icon for each icon */ 
     var leafletIcon = L.Icon.extend({ 
      iconUrl: venues[i]['venue']['categories'][0]['icon'], 
      shadowUrl: null, 
      iconSize: new L.Point(32,32), 
      iconAnchor: new L.Point(16, 41), 
      popupAnchor: new L.Point(0, -51) 
     }); 
     var icon = new leafletIcon(); 
     var marker = new L.Marker(latLng, {icon: icon}) 
      .bindPopup(venues[i]['venue']['name'], { closeButton: false }) 
      .on('mouseover', function(e) { this.openPopup(); }) 
      .on('mouseout', function(e) { this.closePopup(); }); 
     map.addLayer(marker); 
     } 
    }) 
    }) 
    //]]> 
    </script> 


</head> 
<body> 
    <div style="width: 100%; height: 100%;" id="map_canvas"></div> 
</body> 
</html> 

답변

관련 문제