2013-01-11 73 views
0

我使用諾基亞地圖nokia.places.search.manager.findPlaces,最多可獲得100個結果。在諾基亞地圖中獲得無限的結果?

但我需要無限的結果約500或1000.我怎樣才能得到它?

我的諾基亞功能:

nokia.places.search.manager.findPlaces({ searchTerm: searchterm, searchCenter: lat,lng , 
limit:100, didYouMean: 5 }); 

回答

0

findPlaces是本地搜索。當地搜索的重點是小範圍內的結果。 地方搜索的限制目前爲100個地方,因爲超出設定距離的地方不被認爲是相關的。無論如何,添加limit參數並不能保證您可以在給定的搜索區域內找到100個相關位置。

這裏的技巧是不要嘗試,以請求1000分的結果,而是利用一個觀察者,並作出一系列最接近的100個結果的地圖移動聚焦異步請求。在任何地圖上放置數千個標記會導致它無法讀取,緩慢且無法響應。

嘗試類似以下內容,當然還有您自己的app id and token

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<!-- 
    Example from Nokia Maps API Playground, for more information visit http://api.maps.nokia.com 
--> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta http-equiv="X-UA-Compatible" content="IE=7; IE=EmulateIE9"/> 
     <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
     <title>Nokia Maps API Example: Search by category</title> 
     <meta name="description" content="Search by category"/> 
     <meta name="keywords" content="search, services, places, category"/> 
     <!-- For scaling content for mobile devices, setting the viewport to the width of the device--> 
     <meta name=viewport content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> 
     <!-- By default we add ?with=all to load every package available, it's better to change this parameter to your use case. Options ?with=maps|positioning|places|placesdata|directions|datarendering|all --> 
     <script type="text/javascript" charset="UTF-8" src="http://api.maps.nokia.com/2.2.3/jsl.js?with=all"></script> 
     <!-- JavaScript for example container (NoteContainer & Logger) --> 
     <style type="text/css"> 
      html { 
       overflow:hidden; 
      } 

      body { 
       margin: 0; 
       padding: 0; 
       overflow: hidden; 
       width: 100%; 
       height: 100%; 
       position: absolute; 
      } 

      #mapContainer { 
       width: 80%; 
       height: 80%; 
       left: 0; 
       top: 0; 
       position: absolute; 
      } 
      #progress { 
       width: 80%; 
       height: 10%; 
       left: 0; 
       top: 80%; 
       position: absolute; 
      } 
      #buttons { 
       width: 80%; 
       height: 10%; 
       left: 0; 
       top: 90%; 
       position: absolute; 
      } 
     </style> 
    </head> 
    <body> 
     <div id="mapContainer"></div> 
     <div id="progress"></div> 

     <script type="text/javascript" id="exampleJsSource"> 
/* Set authentication token and appid 
* WARNING: this is a demo-only key 
* please register on http://api.developer.nokia.com/ 
* and obtain your own developer's API key 
*/ 
nokia.Settings.set("appId", "MY APP ID"); 
nokia.Settings.set("authenticationToken", "MY TOKEN"); 


// Get the DOM node to which we will append the map 
var mapContainer = document.getElementById("mapContainer"); 
// Create a map inside the map container DOM node 
var map = new nokia.maps.map.Display(mapContainer, { 
    // Initial center and zoom level of the map 
    center: [52.51, 13.4], 
    zoomLevel: 13, 
    components: [  
     new nokia.maps.map.component.Behavior() 
    ] 
}); 

var searchManager = nokia.places.search.manager, 
    resultSet; 




// Function for receiving search results from places search and process them 
var processResults = function (data, requestStatus, requestId) { 
    var i, len, locations, marker; 
    if (requestStatus == "OK") { 
     // The function findPlaces() and reverseGeoCode() of return results in slightly different formats 
     locations = data.results ? data.results.items : [data.location]; 
     // We check that at least one location has been found 
     if (locations.length > 0) { 
      // Remove results from previous search from the map 
      if (resultSet) map.objects.remove(resultSet); 
      // Convert all found locations into a set of markers 
      resultSet = new nokia.maps.map.Container(); 
      for (i = 0, len = locations.length; i < len; i++) { 
       marker = new nokia.maps.map.StandardMarker(locations[i].position, { text: i+1 }); 
       resultSet.objects.add(marker); 
      } 
      // Next we add the marker(s) to the map's object collection so they will be rendered onto the map 
      map.objects.add(resultSet); 
      // We zoom the map to a view that encapsulates all the markers into map's viewport 
      //map.zoomTo(resultSet.getBoundingBox(), true); 

     } else { 
      //alert("Your search produced no results!"); 
     } 
     searching = false; 
    } else { 
     alert("The search request failed"); 
     searching = false; 
    } 
}; 



// Binding of DOM elements to several variables so we can install event handlers. 
var progressUiElt = document.getElementById("progress"); 

// This function is called whenever we make a search 
var searching = false; 
search = function(searchCenter){ 
// Make a place search request 
var category = "eat-drink" 
progressUiElt.innerHTML = "Looking for places in the '" + category + "' category...'"; 
searchManager.findPlacesByCategory({ 
    category: category, 
    onComplete: processResults, 
    searchCenter: searchCenter, 
    limit: 50, 
}); 
} 


search(new nokia.maps.geo.Coordinate(52.51, 13.4)); 



// This observer will call the search function if the center of the map is moved 
// Beyond the area covered in the previous search 
var centerObserver = function (obj, key, newValue, oldValue) { 
    if ((searching == false) && (resultSet.getBoundingBox().contains(newValue) == false)){ 
     searching = true; 
     search(newValue); 
    } 

}; 

map.addObserver("center", centerObserver); 


     </script> 
    </body> 
</html> 
+0

並且怎麼樣使用響應裏面的「下一個」值,這樣就可以得到最好的響應分頁的可能性,請參閱:http://developer.here.com/docs/places /topics/pagination-collections.html 還有:http://developer.here.com/docs/places/topics/object-paginateable-collections.html 我想你應該考慮直接使用REST服務並獲得從這項服務中獲得整套可能性。 –

+0

這裏的問題是如何從一個*限制*聚焦搜索得到的值的*無限*號 - 即使分頁你最終會得到一個響應,其中next()函數是空白的。我同意實現你自己的RESTful包裝會給你更多的可能性。 –