Skip to content

Instantly share code, notes, and snippets.

@adilkurniaramdan
Created December 16, 2014 15:14

Revisions

  1. adilkurniaramdan created this gist Dec 16, 2014.
    78 changes: 78 additions & 0 deletions angular-google-map piece of code
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,78 @@
    angular.extend $scope,
    rad:150
    circles: []
    markers: []
    clickedMarker:
    id: 0
    title: ""
    map:
    control: {}
    center:
    latitude: -6.908659
    longitude: 107.611163
    zoom: 17
    dragging: false
    bounds: {}
    markers: []
    events:
    click: (mapModel, eventName, originalEventArgs) ->
    $timeout ->
    e = originalEventArgs[0]
    lat = e.latLng.lat()
    lon = e.latLng.lng()
    $scope.clickedMarker =
    id: 0
    title: "You clicked here " + "lat: " + lat + " lon: " + lon
    latitude: lat
    longitude: lon
    console.log "You clicked here " + "lat: " + lat + " lon: " + lon
    $scope.circles = []
    console.log $scope.rad
    $scope.circles.push
    id: 1
    center:
    latitude: lat
    longitude: lon
    radius: +$scope.rad
    stroke:
    color: "#08B21F"
    weight: 2
    opacity: 1
    fill:
    color: "#08B21F"
    opacity: 0.2
    geodesic: true # optional: defaults to false

    $scope.markers = []
    $http.post '/api/algorithms/nearestsplace',
    lat: $scope.clickedMarker.latitude
    lon: $scope.clickedMarker.longitude
    radius: +$scope.rad
    .success (data) ->
    id = 0
    $scope.places = data
    $scope.places.forEach (v)->
    v.onClick = ->
    v.show = true
    console.log "Clicked!"
    v.id = id
    v.icon = 'assets/images/icon/parking_bicycle-2.png'
    v.latitude = v.loc.coordinates[1]
    v.longitude = v.loc.coordinates[0]
    arg1 = $scope.clickedMarker.latitude
    arg2 = $scope.clickedMarker.longitude
    arg3 = v.latitude
    arg4 = v.longitude
    v.distance = CalculateDistance arg1, arg2, arg3, arg4
    d = NearestPlaceService arg1, arg2, arg3, arg4, 'K'
    radius = $scope.rad / 1000
    $scope.markers.push(v) if radius > d
    id++
    ,3000
    # $scope.$apply()
    idle: (map) ->
    bounds = map.getBounds()
    ne = bounds.getNorthEast() # LatLng of the north-east corner
    #console.log("ne bounds " + ne.lat() + ", " + ne.lng());
    sw = bounds.getSouthWest() # LatLng of the south-west corder
    return