1

I am using a hash for parameters to be used in generating a URL. I have something like this:

params = {
  :center => Geocoder.coordinates(currentlocation).join(","),
  :zoom => 10,
  :size => "460x280",
  :markers => Geocoder.coordinates(markerlocation).join(","),
  :sensor => true,
  :key => ENV["GOOGLE_API_KEY"]
  }

query_string =  params.map{|k,v| "#{k}=#{v}"}.join("&")
image_tag "https://maps.googleapis.com/maps/api/staticmap?#{query_string}", :alt => location

However I need to have multiple "markers" parameters in the URL. For each URL I generate I won't know how many "markers" parameters I need. For example if I have an array markerlocations I will need to create a :markers key-value pair for each member of the array for use in the URL. What is the best way to accomplish this?

1 Answer 1

1
require 'net/http'
params = {
  :center => Geocoder.coordinates(currentlocation).join(","),
  :zoom => 10,
  :size => "460x280",
  :markers => [Geocoder.coordinates(markerlocation).join(",")],
  :sensor => true,
  :key => ENV["GOOGLE_API_KEY"]
  }
query_string = URI.encode_www_form(params)
image_tag ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.