The MapView class provides an embeddable map interface, similar to the one provided by the Maps application. Click the links below for detailed information about the MapView API methods.
The supported providers are ‘Google’, ‘ESRI’, “RhoGoogle” and “OSM”.
To use ESRI maps in your projects on iPhone:
To use native Google map view on Android:
Add ‘apikey’ parameter and ‘gmaps’ extension to your build.yml
android: apikey: <YOUR-GOOGLE-PLAY-API-KEY> extensions: [gmaps]
Add ‘network_state’ and ‘sdcard’ capabilities to your build.yml.
capabilities: - network_state
Map settings in rhoconfig.txt :
The following code in your controller has the map appear on a whole page.
Ruby example:
map_params = { :provider => 'Google', :settings => {:map_type => "hybrid",:region => [@params['latitude'], @params['longitude'], 0.2, 0.2], :zoom_enabled => true,:scroll_enabled => true,:shows_user_location => false, :api_key => 'Google Maps API Key'}, :annotations => [{:latitude => @params['latitude'], :longitude => @params['longitude'], :title => "Current location", :subtitle => ""}, {:street_address => "Cupertino, CA 95014", :title => "Cupertino", :subtitle => "zip: 95014", :url => "/app/GeoLocation/show?city=Cupertino"}, {:street_address => "Santa Clara, CA 95051", :title => "Santa Clara", :subtitle => "zip: 95051", :url => "/app/GeoLocation/show?city=Santa%20Clara", :pass_location => true}] } MapView.create map_params
JavaScript example:
var map_params = { provider: 'Google', settings: { map_type: 'hybrid', region: [@params['latitude'], @params['longitude'], 0.2, 0.2], zoom_enabled: true, scroll_enabled: true, shows_user_location: false, api_key: 'Google Maps API Key' }, annotations: [ {latitude: @params['latitude'], longitude: @params['longitude'], title: "Current location", subtitle: ""}, {street_address: "Cupertino, CA 95014", title: "Cupertino", subtitle: "zip: 95014", url: "/app/GeoLocation/show?city=Cupertino"}, {street_address: "Santa Clara, CA 95051", title: "Santa Clara", subtitle: "zip: 95051", url: "/app/GeoLocation/show?city=Santa%20Clara"} ] }; Rho.MapView.create(map_params);
You can enable file caching for map tiles - file cache can use for offline map browsing.
MapView.set_file_caching_enable(1)
Preload map tiles for region (0<=zoom<=18): :::ruby def preload_callback puts ‘@@@@@@@@@ Preload Callback STATUS[’+@params[‘status’]+‘] PROGRESS[’+@params[‘progress’]+‘]’ end
def preload_map options = { :engine => 'OSM', :map_type => 'roadmap', :top_latitude => 60.1, :left_longitude => 30.0, :bottom_latitude => 59.7, :right_longitude => 30.6, :min_zoom => 9, :max_zoom => 11 } total_tiles_for_preload_count = MapView.preload_map_tiles(options, url_for(:action => :preload_callback)) redirect :action => :index end
See GeoLocation/controller.rb of system API sample application for some of the examples of how to use MapView class.