Skip to content

Instantly share code, notes, and snippets.

@sgringwe
Created December 11, 2014 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgringwe/f7d9859417d8638abf25 to your computer and use it in GitHub Desktop.
Save sgringwe/f7d9859417d8638abf25 to your computer and use it in GitHub Desktop.
Google maps geocode error
# Asyncronously load the script
loadScript = ->
script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&' + 'callback=initialize';
document.body.appendChild(script)
# Callback after script is loaded
window.initialize = ->
window.geocoder = new google.maps.Geocoder();
return unless Handshake.passed.location_data
if Handshake.passed.map_zoom_level
zoom_level = parseInt($.trim(Handshake.passed.map_zoom_level))
else
zoom_level = 10
mapOptions = {
center: new google.maps.LatLng(37.7833, 122.4167),
zoom: zoom_level,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
window.map = new google.maps.Map(document.getElementById("location_map"), mapOptions)
showAddress(Handshake.passed.location_data, window.map)
geocodeReturned = (results, status) ->
console.log 'c'
console.log results
console.log status
if status is google.maps.GeocoderStatus.OK
map.setCenter results[0].geometry.location
marker = new google.maps.Marker(
map: window.map,
position: results[0].geometry.location
)
else
console.log "Geocode was not successful for the following reason: " + status
# Helper method to load the script
showAddress = (address) ->
try
window.geocoder.geocode({ address: address }, geocodeReturned)
catch error
console.log 'caught error'
console.log error
# Only load the script and initialize on certain pages
# path = window.location.pathname.split('/')
$ ->
if $('#location_map').length > 0
window.onload = loadScript
# Output:
#{:line_number=>0, :message=>"TypeError: Unable to delete property.", :source=>"undefined"}
#{:line_number=>60033, :message=>"c", :source=>"http://127.0.0.1:54046/assets/application.js"}
#{:line_number=>60033, :message=>"[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]", :source=>"http://127.0.0.1:54046/assets/application.js"}
#{:line_number=>60033, :message=>"OK", :source=>"http://127.0.0.1:54046/assets/application.js"}
#{:line_number=>0, :message=>"TypeError: Unable to delete property.", :source=>"undefined"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment