2014-10-08 28 views
1

由於某種原因,在我正在處理的網站上,「舊金山」在Google GeoChart Visualization中將路標放置在路易斯安那州。我甚至試圖將它改爲「舊金山,加利福尼亞州」,甚至是「美國加利福尼亞州舊金山」,它仍然在密歇根州進行陰謀。Google GeoChart可視化API - 錯誤位置的城市繪圖

你可以看到不正確的標記位置:我的代碼http://galmeetsglam.com/travel/

部分:

var data = new google.visualization.DataTable(); 

data.addColumn('string', 'Slug'); 
data.addColumn('string', 'City');   
data.addColumn('number', 'Value'); 
data.addColumn({type: 'string', role: 'tooltip', p:{html:true}}); 

/* Locations */ 
data.addRows([ 
    ['london', 'London', 1, '<h1 class="tooltip-h1">London</h1>'], 
    ['london', 'London', 1, '<h1 class="tooltip-h1">London</h1>'], 
    ['new-york-city', 'New York City', 1, '<h1 class="tooltip-h1">New York City</h1>'], 
    ['san-francisco-2', 'San Francisco', 1, '<h1 class="tooltip-h1">San Francisco</h1>'], 
    ['san-francisco-2', 'San Francisco', 1, '<h1 class="tooltip-h1">San Francisco</h1>'], 
]); 

的奇數部分是其他城市正在策劃就好(倫敦和紐約)。不知道爲什麼SF會扭曲。

任何想法?

回答

1

不知道你爲什麼使用san-francisco-2,但你應該使用San Francisco就像你的第二列或給出的ISO代碼:US-CA。所以:

data.addRows([ 
    ['london', 'London', 1, '<h1 class="tooltip-h1">London</h1>'], 
    ['london', 'London', 1, '<h1 class="tooltip-h1">London</h1>'], 
    ['new-york-city', 'New York City', 1, '<h1 class="tooltip-h1">New York City</h1>'], 
    ['San Francisco', 'San Francisco', 1, '<h1 class="tooltip-h1">San Francisco</h1>'], 
    ['San Francisco', 'San Francisco', 1, '<h1 class="tooltip-h1">San Francisco</h1>'], 
]); 
+0

是的,我有slu and和城市名稱倒退。我只是重新安排了他們,這是很好的去。 – Corey 2014-10-08 20:12:25

+1

很高興你有它的工作,與你的好運 – juvian 2014-10-08 20:15:26

1

在Google Visualization API論壇中找到了答案。

基本上GeoChart使用地理編碼的第一個元素。我有我的類別slu first首先(我用於過濾機制與同位素)。

所以,如果我重新安排我的數據是:

var data = new google.visualization.DataTable(); 

data.addColumn('string', 'City'); 
data.addColumn('string', 'Slug');   
data.addColumn('number', 'Value'); 
data.addColumn({type: 'string', role: 'tooltip', p:{html:true}}); 

/* Locations */ 
data.addRows([ 
    ['London', 'london', 1, '<h1 class="tooltip-h1">London</h1>'], 
    ['London', 'london', 1, '<h1 class="tooltip-h1">London</h1>'], 
    ['New York City', 'new-york-city', 1, '<h1 class="tooltip-h1">New York City</h1>'], 
    ['San Francisco', 'san-francisco-2', 1, '<h1 class="tooltip-h1">San Francisco</h1>'], 
    ['San Francisco', 'san-francisco-2', 1, '<h1 class="tooltip-h1">San Francisco</h1>'], 
]); 

它完美。只要回答這個問題,就可以爲將來的訪問者提供同樣的問題。