Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add place_to to location result #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/google_maps/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
module Google
module Maps
class Location
attr_reader :address, :latitude, :longitude, :components
attr_reader :address, :latitude, :longitude, :place_id, :components
alias to_s address

def initialize(address, latitude, longitude, components = {})
def initialize(address, latitude, longitude, place_id, components = {})
@address = address
@latitude = latitude
@longitude = longitude
@place_id = place_id
@components = components
end

Expand All @@ -27,6 +28,7 @@ def self.find(address, language = :en)
result.formatted_address,
result.geometry.location.lat,
result.geometry.location.lng,
result.place_id,
format_components(result.address_components)
)
end
Expand Down
3 changes: 2 additions & 1 deletion spec/fixtures/geocoder/amsterdam-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@
}
}
},
"place_id" : "ChIJVXealLU_xkcRja_At0z9AGY",
"types" : [ "locality", "political" ]
}
],
"status" : "OK"
}
}
3 changes: 2 additions & 1 deletion spec/fixtures/geocoder/science-park-400-amsterdam-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@
}
}
},
"place_id" : "ChIJIcrTFogJxkcRb0dbtBG4pQc",
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
}
3 changes: 2 additions & 1 deletion spec/fixtures/geocoder/science-park-400-amsterdam-nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@
}
}
},
"place_id" : "ChIJIcrTFogJxkcRb0dbtBG4pQc",
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
}
9 changes: 9 additions & 0 deletions spec/google_maps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
expect(components['route']).to eq(['Science Park Amsterdam'])
expect(components['street_number']).to eq(['400'])
expect(components['sublocality']).to eq(%w[Middenmeer Watergraafsmeer])
expect(location.place_id).to eq('ChIJIcrTFogJxkcRb0dbtBG4pQc')
end

it 'should handle multiple location for an address' do
Expand All @@ -80,6 +81,7 @@
expect(location.address).to eq('Amsterdam, NY, USA')
expect(location.latitude).to eq(42.93868560)
expect(location.longitude).to eq(-74.18818580)
expect(location.place_id).to eq('ChIJVXealLU_xkcRja_At0z9AGY')
end

it 'should accept languages other than en' do
Expand All @@ -89,6 +91,13 @@
expect(location.address).to eq('Science Park 400, Amsterdam, 1098 XH Amsterdam, Nederland')
end

it 'should return place_id' do
stub_response('geocoder/science-park-400-amsterdam-nl.json')

location = Google::Maps.geocode('Science Park 400, Amsterdam', :nl).first
expect(location.place_id).to eq('ChIJIcrTFogJxkcRb0dbtBG4pQc')
end

it 'should return an empty array when an address could not be geocoded' do
stub_response('zero-results.json')

Expand Down