2016-02-11 110 views
0

以下是打開infoWindow時的樣子。如何在打開infoWindow時將其放置在右上角,並有任何方式將其設置爲純矩形。在Google地圖上定位infoWindow

screenshot of map

我的代碼看起來象

var getDirection = new google.maps.InfoWindow({ 
     content: '' 

    }); 

var html ='<address><br>'+fromAddress+'</address><p>get directions from:</p><input id="from_Address" type="text" required><button id="go">Go</button><p><br><p id="error_msg" style="color:red;"></p><br>example: 121 belved Rd CA' 
    getDirection.setContent(html); 
     getDirection.open(resultsMap); 

請幫助。

+0

請檢查:https://developers.google.com/maps/documentation/javascript/infowindows – Microsmsm

+0

謝謝它將有所幫助 –

+0

使用第二個參數('anchor'參數)'打開(map?:Map | StreetViewPanorama,錨?:MVCObject)'或設置InfoWindow的位置。請提供一個[最小,完整,測試和可讀的示例](http://stackoverflow.com/help/mcve)來解決問題。 – geocodezip

回答

0

使用第二個參數(錨參數)打開(Map?:Map | StreetViewPanorama,anchor?:MVCObject)或設置InfoWindow的位置。

var html ='<address><br>'+fromAddress+'</address><p>get directions from:</p><input id="from_Address" type="text" required><button id="go">Go</button><p><br><p id="error_msg" style="color:red;"></p><br>example: 121 belved Rd CA' 
getDirection.setContent(html); 
getDirection.open(resultsMap,marker); 
0

沿this solution的線以下,請參見下面的代碼示例:

var center = JSON.parse(JSON.stringify(map.getCenter())); 
var boundaries = JSON.parse(JSON.stringify(map.getBounds())); 
var newPosition = {lat: center.lat + Math.abs(boundaries.north - center.lat)/2.75, lng: center.lng}; 
infoWindow.setContent('<strong>This infowindow should be located near the top, approx in the middle between the top point and the middle point.</strong>'); 
infoWindow.setPosition(newPosition); 

基本上,你可以在地圖的邊界,你有中心點。你所要做的就是用這些參數計算新的位置。

希望這會有所幫助。