0

次のコードはマップをレンダリングしますが、コールバックはクリック イベントで実行されません。何か案は?

google.maps.visualRefresh = true
url = 'http://localhost:3000/closeby'

getCloseBy = (pos) ->
    $.post url, {'center': pos}

initialize = ->
    mapOptions = 
        zoom: 15
        mapTypeId: google.maps.MapTypeId.ROADMAP
    map = new google.maps.Map document.getElementById('map-canvas'), mapOptions

    if navigator.geolocation
    navigator.geolocation.getCurrentPosition (position)->
        pos = new google.maps.LatLng position.coords.latitude, position.coords.longitude
        infowindow = new google.maps.InfoWindow
            map: map
            position: pos
        map.setCenter pos
    , ->
        handleNoGeolocation true        
    else 
    handleNoGeolocation false       

  handleNoGeolocation = (errorFlag) ->
        if errorFlag
            content = 'Geolocation failed'
        else
            content = 'Your browser does not support Geolocation'
        options = 
            map: map
            position: new google.maps.LatLng 60, 105
            content: content
        infowindow = new google.maps.InfoWindow options
        map.setCenter options.position

  placeMarker = (location) ->
    marker = new google.maps.Marker
        position: location
        map: map

  google.maps.event.addListener map, 'click', (event)->
    placeMarker event.latLng    

google.maps.event.addDomListener window, 'load', initialize
4

1 に答える 1