I am trying to control the zoom level of a map that is using openlayers as the map provider.
gmaps({
"map_options" => { "provider" => "openlayers",
"auto_zoom" => false, "zoom" => 12 },
"markers" => { "data" => #json }
})
The map (from OpenStreetMap) gets displayed but the zoom level remains the same no matter what value I use for the zoom option. The same code above without the "provider" => "openlayers" option works as expected for google maps.
The wiki for gmaps4rails has a link to a spreadsheet which states that "Zoom" is supported (but not "auto-zoom") for OpenLayers API.
So, is zoom control supported? Or am I doing something wrong?
Related
Hi I am currently working on a trash bin/recycling bin location application using google maps for rails.
I have a recyclingbin.rb model with the address as its attributes, that itself is enough to put markers on a map that can get displayed using the gem. I believe the gem converts the model and its attributes into json data.
I am trying to implement a feature where I can input my location and get direction to the nearest marker.
I have looked at the wiki , https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Direction
Am I suppose to put this in the view ?
{ "data" => { "from" => "Paris, france", "to" => "Toulon, france" } }
})
%>
with the from to be embedded with my location for now? I understand I can pass options to this reference from google.
The wiki is quite short, can someone give me a quick explanation ?
The wiki does need some more work. I have a simple app working that shows the directions on the map from a location to another (pre-defined) location
<%= gmaps("map_options" => {"zoom" => 14}, "markers" => { "data" => #json },
"direction" => { "data" => {"from" => #location.address, "to" => "New York City"},"travelMode" => "DRIVING"}) %>
I just put this in my view. It shouldn't matter where, just as long as its there. Hope this helps
I am working with gem "gmaps4rails" in rails 3.2.12, I had set the detect_location = "true" in map_options, but it is not showing any marker with user current location.
Here is code:
<%= gmaps("map_options" => {"auto_adjust" => true, "detect_location" => true, "center_on_user" => true, "auto_zoom" => false, "radius" => 2500},
"markers" => {"data" => #json, "options" => {"list_container" => "markers_list","randomize" => true,"max_random_distance" => 10000, "draggable" => true, "dblclick" => "latLng"} }
How to show with marker for the user current location.
Please help me.
Thanks in Advance
With the gem "gmaps4rails",
if we give the option "detect_location" => true, when the map loads on page, it shows pop-up to user as 'allow application to use your location' and gives yes and no as options.
If user selects 'yes', then map get centered to user's location.
Now here you want to display marker for user's location, then you have to add marker by your own.
This can be done as follows:
Controller:
geo = request.location
#latitude = geo.latitude
#longitude = geo.longitude
With your page load, you can add marker for user, with this callback.
This would add marker for current user location when map loads on page.
- content_for :scripts do
%script{:type => "text/javascript"}
Gmaps.map.callback = function(){
google.maps.event.addListenerOnce(Gmaps.map.serviceObject, 'idle', function(){
/ add user pin
var home_pin = [{picture: "current_user.png", width: 32, lat: "#{#latitude}", lng: "#{#longitude}"}];
Gmaps.map.addMarkers(home_pin)
}
)};
Hope this would help you.
Let me know if you still face any issues.
Thanks.
I can currently draw polylines using gmaps4rails in Rails but I'd like to draw them as geodesic paths. According to the Google Map documentation this should be as simple as adding "geodesic: true" to the options (link). Below is my current implementation that doesn't work but simply draws a straight line on the map. Is there a correct way of setting this option in gmaps4rails or is this not currently supported?
In my controller:
#json_route =
[
[
{'lng' => 80.190262, 'lat' => 55.774252 },
{'lng' => -66.118292, 'lat' => 38.466465 }
]
]
#gmaps_options =
{
:polylines => { "data" => #json_route.to_json, "options" => { "geodesic" => true }}
}
In my html page:
<%= gmaps(#gmaps_options) %>
Thank you!
I am wondering how to deal with the situation where one location may have many markers.
I am using gmaps4rails and rails 3
does this have something to do with the "do_clustering" property of the gmaps?
Thanks!
Adam
excellent, just found "randomize" in the documentation! perfect:
{:data => #json, :options => { :do_clustering => true, randomize: true} }) %>
To implement Gravatar in my Rails3 application, I'm using the gravatar_image_tag gem in a helper, but I'm having issues when mixing 2 config options:
If the user doesn't have a gravatar attached to his email a default image is rendered; but I want it to reference an external file (e.g., http://www.iconfinder.com/ajax/download/png/?id=43350&s=128 instead of :identicon or others)
I also want the image to be resized on the fly to, let's say 50px.
Independently, both options work as expected, but when I put them together:
def gravatar_for(user, options = { :default => 'http://www.iconfinder.com/ajax/download/png/?id=43350&s=128', :size => 50 })
gravatar_image_tag(user.email.downcase, :alt => user.full_name,
:class => 'gravatar',
:gravatar => options)
end
the size option is not applied, and the gravatar gets rendered in it's full size (128px in this case).
What am I doing wrong, or how can I achieve this combination?
Gravatar will not resize your default image for you. I assume that it just 302s to the ulr gave as a default if it does not find an gravatar for the email you gave it. It looks like the 's' parameter in the iconfinder url is for the size you are trying to grab but that icon does not have a size of 50px available only 128, 256, and 512
Example:
http://www.iconfinder.com/ajax/download/png/?id=43350&s=256
If you wanted a 50px and 80px versions of the icon I would save it to your applications public/image directory as default_gravatar_50.png and default_gravatar_80.png respectively and change your method like so.
end
def gravatar_for(user, options = {})
options = { :size => 50 }.merge(options)
options[:default] = image_tag("default_gravatar_#{options[:size]}.png
gravatar_image_tag(user.email.downcase,
:alt => user.full_name,
:class => 'gravatar',
:gravatar => options)
end
Or if you find an icon on icon finder that is the size(s) you like change the setting of the default option like so.
options[:default] = "http://www.iconfinder.com/ajax/download/png/?id=43350&s=#{options[:size]}"
Iconfinder here. You don't want to link to the download script. Instead just grab the URL to the image it self so you wan't get a lot of header information.