map.js.coffee
jQuery ->
  getLocation = ->
    if navigator.geolocation
      navigator.geolocation.getCurrentPosition userPosition showError options
    else
      alert("Geolocation is not supported by this browser.")
  handler = Gmaps.build 'Google'
  handler.buildMap 
    provider: {}
    internal: {id: 'map'}
  , ->
    handler.panTo latlng
geolocation.js.coffee
userPosition = (position) ->
  latlng = new google.maps.LatLng(position.coords.latitude + "," + position.coords.longitude)
  alert(latlng)
showError = (error) ->
  switch error.code
    when error.PERMISSION_DENIED
      alert("User denied the request for Geolocation.")
    when error.POSITION_UNAVAILABLE
      alert("Location information is unavailable.")
    when error.TIMEOUT
      alert("The request to get user location timed out.")
    when error.UNKNOWN_ERROR
      alert("An unknown error occurred.")
options =
  enableHighAccuracy: false
  timeout: 5000
我觉得也许我没有掌握全局变量?我试着把getLocation电话到处移动......
我尝试将它们全部放在同一个文件中...
我尝试将处理程序移动到就绪函数的上方(外部)jQuery......这给出了关于 _ 未定义的不同错误。
我把它扔alert(latlng)在那里只是为了看看它是否甚至达到了那个功能......它不是。
我正在尝试新的gmaps4rails gem并且有点挣扎。我也查看了W3schools的信息,这段代码非常接近。