2013-06-03 63 views
0

我在學習如何使用Google Local Search API。我無法將本地搜索中心設置爲巴基斯坦。請指導我。謝謝。在Google搜索中設置中心點

與問題代碼的行是:

localSearch.setCenterPoint("Pakistan, PAK"); 

的小提琴表示正在顯示的是從紐約結果是here

整個代碼,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/> 
    <title>Hello World - Google Web Search API Sample</title> 
    <script src="https://www.google.com/jsapi" 
     type="text/javascript"></script> 
    <script language="Javascript" type="text/javascript"> 
    //<! 

    //google.load('search', '1'); 
    google.load("search", "1", {"nocss" : true}); 

    function OnLoad() { 
     // Create a search control 
     var searchControl = new google.search.SearchControl(); 

     // Add in a full set of searchers 
     var localSearch = new google.search.LocalSearch(); 

     searchControl.addSearcher(new google.search.NewsSearch()); 

     // Set the Local Search center point 
     localSearch.setCenterPoint("Pakistan, PAK"); 

     // tell the searcher to draw itself and tell it where to attach 
     searchControl.draw(document.getElementById("searchcontrol")); 

     // execute an inital search 
     searchControl.execute("Facebook"); 
    } 
    google.setOnLoadCallback(OnLoad); 

    //]]> 
    </script> 
    </head> 
    <body> 
    <div id="searchcontrol">Loading</div> 
    </body> 
</html> 

回答

0

我相信你需要知道PAK的緯度和經度就是爲它找到它。

setCenter(latlng:LatLng);

+0

否參閱:https://code.google.com/apis/ajax/playground/#geo_restriction –