2014-07-18 2 views
0

Google지도에서 일부 POI를 클릭하면지도 엔진이 시스템 기본 정보 창을 엽니 다. 어떻게 그 창에 대한 참조를 얻습니까? 다음에지도를 클릭하면 닫을 수 있습니다.시스템 정보 창을 어떻게 참조합니까?

+0

당신은 사람들을 참조 할 수 없습니다

나는 작은 데모를 준비했다. – geocodezip

+0

좋은 의견이없는 투표와 가까운 투표. – Kolyunya

+0

가능한 중복 [Google지도 API의 흥미로운 장소의 기본 정보 창과 작업] (http://stackoverflow.com/questions/21202034/work-with-native-infowindows-of-interesting-places-in-google-maps- api/21884991 # 21884991) – geocodezip

답변

2

전에 몇 가지 비슷한 질문이 계속있다 :

:

//run this after loading the maps-api 

(function(){ 
    var fx = google.maps.InfoWindow.prototype.setContent; 

    //override the built-in setContent-method 
    google.maps.InfoWindow.prototype.setContent = function() { 

    //this property isn't documented, but as it seems 
    //it's only defined for InfoWindows opened on POI's 
    if (this.logAsInternal) { 
     google.maps.event.addListenerOnce(this, 'map_changed',function() { 
     var map = this.getMap(),that=this; 
     //attach the click-handler when the infowindow opens 
     if (map) { 
      google.maps.event.addListenerOnce(map, 'click', function(){that.close();}); 
     } 
     }); 
    } 
    //call the original setContent-method 
    fx.apply(this, arguments); 
    };})(); 

데모 : http://jsfiddle.net/doktormolle/Q7Gbb/

3

Google지도 API 문제 추적기에서 추적되는 문제 # 4797이며 최근에 수정되어 버전 3.26에서 사용할 수 있습니다.

버전 3.26부터 Map 객체의 "click"이벤트를 수신해야합니다. 사용자가 POI를 클릭하면 IconMouseEvent가 발생합니다. 이 클래스는 Regular MouseEvent를 확장하며 placeId라는 속성을 포함합니다. 따라서 이벤트 객체가 placeId를 정의했는지 확인할 수 있습니다. placeId 필드에는 물론 장소 ID가 포함되어 있으며, 클릭 한 아이콘에 대한 자세한 정보를 얻기 위해 Places API와 함께 사용할 수 있습니다. 지도 "클릭"이벤트 핸들러는 다음과 같이한다 한마디로 http://jsbin.com/parapex/10/edit?html,output

:

// This is the click event handler 
var handleClick = function(event) { 
// If the event has a placeId, use it. 
    if (event.placeId) { 
    // Calling e.stop() on the event prevents the default info window 
    // from showing. 
    // If you call stop here when there is no placeId you will prevent 
    // some other map click event handlers from receiving the event. 
    event.stop(); 
    // do something with event.placeId here. Like calling places service 
    } 
}; 
관련 문제