-
Notifications
You must be signed in to change notification settings - Fork 382
Map Apis
Since 0.10.0, you can choose your map API from the following:
-
Google Maps (of course...)
-
Openlayers
-
Mapquest
-
Bing
-
Yandex.Maps APIv2
<%= gmaps("markers" => {"data" => @json},
"map_options" => { "provider" => "openlayers"}) %>
For bing and mapquest, you need to provide an API key. Simply pass it as an argument:
<%= gmaps("markers" => {"data" => @json},
"map_options" => { "provider" => "mapquest", "provider_key" => MAPQUEST_KEY, "auto_adjust" => true,"center_on_user" => true }) %>
Or:
<%= gmaps("markers" => {"data" => @json},
"map_options" => { "zoom" => 5, "provider" => "bing", "provider_key" => BING_KEY, "auto_adjust" => true,"center_on_user" => true }) %>
Not every method I created for google maps is implemented in the other APIs. See current state of other APIs implementation
If you lack some options for maps and markers, you can simply pass what you need in :raw
:
<%= gmaps(:markers => {:data => @json, :options => { :raw => '{ animation: google.maps.Animation.BOUNCE }' } },
:map_options => { :raw => '{ disableDefaultUI: true, scrollwheel: false }' }) %>
Infowindows are stored to allow callback access: Gmaps.map.markers[0].infowindow
The gmaps
helpers load the google maps api:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry"></script>
If you want to load additional apis (such as places
), simply pass them in the hash:
<%= gmaps({
"map_options" => {"libraries" => ["places"] },
... #add here data you want to display
})
%>
If you want to pass special options for localization, you can pass them in the hash:
<%= gmaps({
"map_options" => {:language => 'ru', :hl => 'ru', :region => 'ru'}
})
%>
more info: https://developers.google.com/maps/documentation/javascript/basics#Localization
For Infowindows, you can have description
which is raw text or htmlContent
:
<%= gmaps("markers" => {"data" => @json, "options" => {"infobox" => "htmlContent" } }) %>
For Map type, you have the choice among: aerial, auto, birdseye, collinsBart, mercator, ordnanceSurvey and road (default).