开发者

geocoding rails

I am trying to geocode multiple addresses in a model using either geokit or geocoder and I can't get either on of the gems to work as I want them to.开发者_运维技巧 Here is the code that I am applying to my model for both use cases and the errors I get for each option.

The Geocoder gist: https://gist.github.com/112cc28b7d52402079ad

The Geokit gist https://gist.github.com/adef30cb458c1177df2b

I am using devise, and rails 3.1 if that helps, and I am fairly certain that I am close to the correct code in the geocoder option, but don't know what I am doing wrong.


I defined my own custom geocoding method similar to this:

def custom_geocode
   var = Geocoder.coordinates(self.address1)
   var2 = Geocoder.coordinates(self.address2)
   self.latitude1 = var.first
   self.longitude1 = var.last
   self.latitude2 = var2.first
   self.longitude2 = var2.last
end

Geocoder.coordinates returns an array of the latitude and longitude from the resulting address, and you save the resulting latitudes and longitudes.


dont know geocoder, but i entered your shipping_address on this demo site for geocoder and it seems the response is an array. Your error message says that you're calling the latitude method on an array and ruby is angry about it. try using this instead :

start_result[0].latitude
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜