Skip to content

Instantly share code, notes, and snippets.

@saarons
Created April 30, 2010 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save saarons/384713 to your computer and use it in GitHub Desktop.
Save saarons/384713 to your computer and use it in GitHub Desktop.
$(document).ready ->
gSmallShadow: new google.maps.MarkerImage("http://labs.google.com/ridefinder/images/mm_20_shadow.png", new google.maps.Size(22, 20), new google.maps.Point(0, 0), new google.maps.Point(6, 20))
gYellowIcon: new google.maps.MarkerImage("http://labs.google.com/ridefinder/images/mm_20_yellow.png", new google.maps.Size(12, 20), new google.maps.Point(0, 0), new google.maps.Point(6, 20))
places: {}
updatePlaces: ->
bounds: map.getBounds()
ne: bounds.getNorthEast()
sw: bounds.getSouthWest()
$.ajax({
url: "/api/near_me"
dataType: "json"
data: {
ne_latitude: ne.lat()
ne_longitude: ne.lng()
sw_latitude: sw.lat()
sw_longitude: sw.lng()
}
success: (data) ->
new_places: {}
for place in data
new_places["${ place.id }"]: new google.maps.Marker({
position: new google.maps.LatLng(place.latitude, place.longitude)
map: map
title: place.name
icon: gYellowIcon
shadow: gSmallShadow
})
for id, place2 of places
if not new_places[id]?
place2.setMap(null)
delete(places[id])
})
setCurrentLocation: ->
$.ajax({
url: "/api/current_location"
dataType: "json"
success: (data) ->
current_lat_lng: new google.maps.LatLng(data.centroid_lat, data.centroid_lon)
player: new google.maps.Marker({
position: current_lat_lng
map: map
title: "You"
draggable: true
})
map.setZoom(13)
map.setCenter(current_lat_lng)
for event_name in ["dragend", "zoom_changed"]
google.maps.event.addListener(map, event_name, ( -> updatePlaces() ) )
google.maps.event.addListener(player, "dragend", (mouse_event) ->
endpoint: player.getPosition()
$.ajax({
type: "POST"
url: "/api/move"
data: {
latitude: endpoint.lat()
longitude: endpoint.lng()
}
dataType: "json"
success: (data) ->
current_lat_lng: new google.maps.LatLng(data.centroid_lat, data.centroid_lon)
player.setPosition(current_lat_lng)
map.panTo(current_lat_lng)
updatePlaces()
})
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment