2012-02-12 45 views
0

我有一張地圖,我想要顯示2個地方:出發和到達。當我展示第一名的時候,我沒有任何問題,但是當我必須展示第二名的時候,我無法用兩個座標來表達意思。這是代碼。在同一地圖上顯示2個或更多地方

   // options for the map of departure only 
       if (coord_arrival == "") 
       { 
        // replacing the previously saved with the new coordinates 
        if (place.geometry.viewport) 
         map.fitBounds(place.geometry.viewport); 
        else { 
         map.setCenter(place.geometry.location); 
         map.setZoom(17); // why 17? because it looks good 
        } 
        coord_departure = place.geometry.location; 
        // HERE IS THE PROBLEM: I can't do anything on this string. Why? 
        coord_departure = coord_departure.replace("(", ""); 
        alert("coordinates of departure: " + coord_departure); 
        // the output will be something like: "(coordX, coordY)" 
       } 

如果你需要它,我也會粘貼2個座標的平均值代碼。謝謝

+0

請問您可以發佈一個鏈接到您的代碼?很難說出你要在這裏做什麼。 – 2012-02-12 13:25:35

回答

1

您可能試圖操縱一個非字符串對象作爲字符串與replace

輸出(x, y)可能是從對象的toString方法返回的值,該方法用於由+運算符觸發的序列化。

您可以自己調用該方法並更改結果。

coord_departure = coord_departure.toString().replace(/\(|\)/g, ''); 
+0

它的作品,非常感謝你! :) – AleVale94 2012-02-12 13:45:03

相關問題