Gemfile

# Gemfile
gem 'gmaps4rails'
gem 'markerclustererplus-rails'
gem 'underscore-rails'
gem 'geocoder'
Manifest

# app/assets/angulars/city_finder.js
//= require jquery
//= require underscore
//= require gmaps/google
//= require markerclusterer
//= require prism

//= require angular
//= require angular-ui-router
//= require angular-rails-templates

//= require_tree './city_finder'
Markup

<zoolu-map geocode="<%= geocode_url %>"></zoolu-map>
Angular

# app/assets/angulars/city_finder/app.coffee
app.directive "zooluMap", [ () ->
  ...
  templateUrl: 'city_finder/zoolu-map.html'
  scope:
    geocode: "@"
  controller: ($scope) ->
    ...
    @gmap_init = () ->
    @displayOnMap = (position) =>
    @termChange = (terms) ->
    @startProcessing = (terms) =>
    @addMarker = (lat, lng, address) ->
    @removeMarkers = () ->
    @
  controllerAs: 'mapCtrl'
  link: (scope, element, attrs, ctrl) ->
    ctrl.gmap_init()
]
Template

<!-- app/assets/angulars/city_finder/zoolu-map.html.erb -->
<div class="panel panel-default">
  <div class="panel-heading form-group">
    <input type="text" class="form-control" id='terms'
          placeholder="Enter cities like london, paris, tokyo"
          ng-model="mapCtrl.terms" ng-change="mapCtrl.termChange(mapCtrl.terms)">
  </div>

  <div class="panel-body">
    <div id="map-canvas" style="height: 400px"></div>
  </div>
</div>
Location API
rails g model location address latitude:float longitude:float
rake db:migrate
vi location.rb

# app/models/location.rb
geocoded_by :address
after_validation :geocode, if: lambda{ |obj| obj.address_changed? }

def self.finder(address)
  # result = Geocoder.search(address)
  if address.present?
    loc = self.find_or_create_by(address: address)
    loc = nil if loc.latitude.nil? or loc.longitude.nil?
    loc
  end
end
rails g controller api/locations index --skip-assets --skip-template-engine --skip-helper
vi locations_controller.rb

# app/controllers/api/locations_controller.rb
def index
  location = Location.finder(params[:address])
  # location = {'latitude' => 36, 'longitude' => 127.5, 'address' => '죽전'}
  if location
    render json: location, status: 200
  else
    render nothing: true, status: 404
  end
end
vi routes.rb

# config/routes.rb
namespace :api, path: '/', constraints: {subdomain: 'api'} do
  resources :locations, only: :index
end
curl -i http://api.example.com:3000/locations?address='서울'