【问题标题】:how to differntiate current location and nearby location using two different markers in gmaps4rails如何使用gmaps rails中的两个不同标记来区分当前位置和附近位置
【发布时间】:2013-01-15 18:12:14
【问题描述】:

我正在使用 gmaps4rails 在我的应用程序中显示 gmap。我正在正确获取地图点,但我无法区分我的地图中的当前位置和 nerby 位置。我的想法是对两个位置使用不同的标记,我在下面做了方式,但它对我没有用

我的控制器

def profile

   @googlemaplocation=Location.find_by_id("#{params[:clinic_id]}")

    @json1 = @googlemaplocation.to_gmaps4rails do |locations, marker|

  marker.picture({
                  :picture => "http://www.google.com/mapfiles/dd-start.png",
                  :width   => 32,
                  :height  => 32
                 })
  end

    @neargooglemaplocation=@googlemaplocation.nearbys(10)
    @json2= @neargooglemaplocation.to_gmaps4rails do |locations, marker|

  marker.picture({
                  :picture => "http://www.google.com/mapfiles/dd-start.png",
                  :width   => 32,
                  :height  => 32
                 })
  end

    @json = (JSON.parse(@json1) + JSON.parse(@json2)).to_json

  end

我的看法

<%= gmaps(:markers => { :data => @json } ) %>

如果我想在同一张地图上显示两个不同的标记该怎么办

感谢和问候 哈里·克里希纳

【问题讨论】:

  • 可能是不同的图片?

标签: ruby-on-rails gmaps4rails


【解决方案1】:

正如 apneadiving 所说,您可以使用不同的图像。例如:

def profile

   @googlemaplocation=Location.find_by_id("#{params[:clinic_id]}")

    @json1 = @googlemaplocation.to_gmaps4rails do |locations, marker|

  marker.picture({
                  :picture => "http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png",
                  :width   => 32,
                  :height  => 32
                 })
  end

    @neargooglemaplocation=@googlemaplocation.nearbys(10)
    @json2= @neargooglemaplocation.to_gmaps4rails do |locations, marker|

  marker.picture({
                  :picture => "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png",
                  :width   => 32,
                  :height  => 32
                 })
  end

    @json = (JSON.parse(@json1) + JSON.parse(@json2)).to_json

  end

顺便说一句:谢谢,我正在寻找一种在我的应用中为附近位置添加标记的方法 :)

问候。

【讨论】:

  • 谢谢。你的回答帮助了我。我也在做同样的事情。
猜你喜欢
  • 2015-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多