├── .gitignore ├── LICENSE.md ├── README.md ├── pom.xml └── src └── main └── java └── com └── claygregory └── api └── google └── places ├── AddressComponent.java ├── AspectRating.java ├── AutocompleteResult.java ├── GooglePlaces.java ├── MatchedSubstring.java ├── OpenPeriod.java ├── OpenTime.java ├── OpeningHours.java ├── Place.java ├── PlaceDetail.java ├── PlaceDetailResult.java ├── PlaceEvent.java ├── PlacePhoto.java ├── PlacesException.java ├── PlacesQueryOptions.java ├── PlacesResult.java ├── Prediction.java ├── Result.java ├── Review.java └── Term.java /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | target 3 | .classpath 4 | .project 5 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2015 Clay Gregory 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Google Places API - Java 2 | 3 | This is a lightweight Java wrapper of the Google Places API supporting common query actions including search, detail, and autocomplete. 4 | 5 | ## Example Usage 6 | 7 | ### Search Nearby 8 | ```java 9 | GooglePlaces places = new GooglePlaces( "API_KEY" ); 10 | PlacesResult result = places.searchNearby( 40.10744f, -88.22724f, 5000, PlacesQueryOptions.create( ).keyword( "siebel center" ) ); 11 | 12 | System.out.println( result.getStatus( ) ); 13 | for ( Place place : result ) 14 | System.out.println( place.getName( ) + " " + place.getGeometry( ).getLocation( ) ); 15 | ``` 16 | 17 | ### Search Text 18 | ```java 19 | GooglePlaces places = new GooglePlaces( "API_KEY" ); 20 | PlacesResult result = places.searchText( "Pizza in Champaign, IL" ); 21 | 22 | System.out.println( result.getStatus( ) ); 23 | for ( Place place : result ) 24 | System.out.println( place.getName( ) + ", " + place.getFormattedAddress( ) ); 25 | ``` 26 | 27 | ### Detail 28 | ```java 29 | GooglePlaces places = new GooglePlaces( "API_KEY" ); 30 | PlaceDetailResult result = places.detail( place.getPlaceId( ) ); 31 | ``` 32 | 33 | ### Autocomplete 34 | ```java 35 | GooglePlaces places = new GooglePlaces( "API_KEY" ); 36 | AutocompleteResult result = places.autocomplete( "Siebel Ce" ); 37 | 38 | for ( Prediction p : result ) 39 | System.out.println( p.getDescription( ) ); 40 | ``` 41 | 42 | ## Dependencies 43 | * [Apache HttpClient](http://hc.apache.org/) 44 | * [GSON](http://code.google.com/p/google-gson/) 45 | 46 | ## License 47 | 48 | See the [LICENSE](LICENSE.md) file for rights and limitations under the terms of the MIT license. 49 | 50 | ## Downloads 51 | 52 | Source is hosted on [GitHub](https://github.com/claygregory/google-places-api-java). 53 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 4.0.0 5 | 6 | com.claygregory 7 | google-places-api-java 8 | 0.3-SNAPSHOT 9 | google-places-api-java 10 | https://github.com/claygregory/google-places-api-java 11 | 12 | 13 | https://github.com/claygregory/google-places-api-java/issues 14 | GitHub Issues 15 | 16 | 17 | 18 | https://github.com/claygregory/google-places-api-java 19 | scm:git:git://github.com/claygregory/google-places-api-java.git 20 | scm:git:git@github.com:fitbit/google-places-api-java.git 21 | 22 | 23 | 24 | 25 | Clay Gregory 26 | https://github.com/claygregory 27 | claygregory 28 | 29 | 30 | 31 | 32 | UTF-8 33 | github 34 | 35 | 36 | 37 | 38 | 39 | maven-assembly-plugin 40 | 41 | 42 | jar-with-dependencies 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.apache.httpcomponents 52 | httpclient 53 | 4.3.2 54 | 55 | 56 | com.google.code.gson 57 | gson 58 | 2.2.2 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/AddressComponent.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | import java.util.Collections; 4 | import java.util.Set; 5 | 6 | public class AddressComponent { 7 | 8 | private String longName; 9 | 10 | private String shortName; 11 | 12 | private Set types = Collections.emptySet( ); 13 | 14 | public String getLongName( ) { 15 | return this.longName; 16 | } 17 | 18 | public String getShortName( ) { 19 | return this.shortName; 20 | } 21 | 22 | public Set getTypes( ) { 23 | return this.types; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/AspectRating.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | public class AspectRating { 4 | 5 | private int rating; 6 | 7 | private String type; 8 | 9 | public int getRating( ) { 10 | return this.rating; 11 | } 12 | 13 | public String getType( ) { 14 | return this.type; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/AutocompleteResult.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | import java.util.Iterator; 4 | import java.util.List; 5 | 6 | 7 | public class AutocompleteResult extends Result implements Iterable { 8 | 9 | private List predictions; 10 | 11 | @Override 12 | public Iterator iterator( ) { 13 | return this.predictions.iterator( ); 14 | } 15 | 16 | public int size( ) { 17 | return this.predictions.size( ); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/GooglePlaces.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | import java.io.IOException; 3 | import java.io.InputStreamReader; 4 | import java.net.MalformedURLException; 5 | import java.net.URISyntaxException; 6 | import java.net.URL; 7 | 8 | import org.apache.http.HttpResponse; 9 | import org.apache.http.client.HttpClient; 10 | import org.apache.http.client.methods.HttpGet; 11 | import org.apache.http.client.utils.URIBuilder; 12 | import org.apache.http.impl.client.HttpClientBuilder; 13 | 14 | import com.claygregory.api.google.places.Place.Location; 15 | import com.google.gson.FieldNamingPolicy; 16 | import com.google.gson.Gson; 17 | import com.google.gson.GsonBuilder; 18 | 19 | 20 | public class GooglePlaces { 21 | 22 | private static final String AUTOCOMPLETE_URL = "https://maps.googleapis.com/maps/api/place/autocomplete/json"; 23 | 24 | private static final String DETAIL_URL = "https://maps.googleapis.com/maps/api/place/details/json"; 25 | 26 | private static final String PHOTO_URL = "https://maps.googleapis.com/maps/api/place/photo"; 27 | 28 | private static final String NEARBY_SEARCH_URL = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"; 29 | 30 | private static final String TEXT_SEARCH_URL = "https://maps.googleapis.com/maps/api/place/textsearch/json"; 31 | 32 | private String apikey; 33 | 34 | private HttpClient client; 35 | 36 | private Gson gson; 37 | 38 | public GooglePlaces( String apikey ) { 39 | this( HttpClientBuilder.create( ).useSystemProperties( ).build( ), apikey ); 40 | } 41 | 42 | public GooglePlaces( HttpClient client, String apikey ) { 43 | this.apikey = apikey; 44 | 45 | GsonBuilder gb = new GsonBuilder( ); 46 | gb.setFieldNamingPolicy( FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES ); 47 | this.gson = gb.create( ); 48 | 49 | this.client = client; 50 | } 51 | 52 | private AutocompleteResult parseAutocompleteResponse( HttpResponse response ) throws IOException { 53 | return this.gson.fromJson( new InputStreamReader( response.getEntity( ).getContent( ) ), AutocompleteResult.class ); 54 | } 55 | 56 | private PlaceDetailResult parseDetailResponse( HttpResponse response ) throws IOException { 57 | return this.gson.fromJson( new InputStreamReader( response.getEntity( ).getContent( ) ), PlaceDetailResult.class ); 58 | } 59 | 60 | private PlacesResult parseSearchResponse( HttpResponse response ) throws IOException { 61 | return this.gson.fromJson( new InputStreamReader( response.getEntity( ).getContent( ) ), PlacesResult.class ); 62 | } 63 | 64 | public AutocompleteResult autocomplete( String input ) { 65 | return autocomplete( input, null ); 66 | } 67 | 68 | public AutocompleteResult autocomplete( String input, PlacesQueryOptions options ) { 69 | try { 70 | URIBuilder url = new URIBuilder( AUTOCOMPLETE_URL ); 71 | url.addParameter( "key", this.apikey ); 72 | url.addParameter( "input", input ); 73 | 74 | if ( options != null ) 75 | for ( String param : options.params( ).keySet( ) ) 76 | url.addParameter( param, options.param( param ) ); 77 | 78 | HttpGet get = new HttpGet( url.build( ) ); 79 | return this.parseAutocompleteResponse( this.client.execute( get ) ); 80 | 81 | } catch( Exception e ) { 82 | throw new PlacesException( e ); 83 | } 84 | } 85 | 86 | public PlaceDetailResult detail( String placeId ) { 87 | try { 88 | URIBuilder url = new URIBuilder( DETAIL_URL ); 89 | url.addParameter( "key", this.apikey ); 90 | url.addParameter( "placeid", placeId ); 91 | 92 | HttpGet get = new HttpGet( url.build( ) ); 93 | return this.parseDetailResponse( this.client.execute( get ) ); 94 | 95 | } catch( Exception e ) { 96 | throw new PlacesException( e ); 97 | } 98 | } 99 | 100 | @Deprecated 101 | public PlaceDetailResult detail( String reference, boolean sensor ) { 102 | try { 103 | URIBuilder url = new URIBuilder( DETAIL_URL ); 104 | url.addParameter( "key", this.apikey ); 105 | url.addParameter( "reference", reference ); 106 | url.addParameter( "sensor", String.valueOf( sensor ) ); 107 | 108 | HttpGet get = new HttpGet( url.build( ) ); 109 | return this.parseDetailResponse( this.client.execute( get ) ); 110 | 111 | } catch( Exception e ) { 112 | throw new PlacesException( e ); 113 | } 114 | } 115 | 116 | public URL photoUrl( String photoReference, Integer maxHeight, Integer maxWidth ) { 117 | 118 | try { 119 | 120 | URIBuilder url = new URIBuilder( PHOTO_URL ); 121 | url.addParameter( "key", this.apikey ); 122 | url.addParameter( "photoreference", photoReference ); 123 | url.addParameter( "maxheight", maxHeight != null ? String.valueOf( maxHeight ) : null ); 124 | url.addParameter( "maxwidth", maxWidth != null ? String.valueOf( maxWidth ) : null ); 125 | 126 | return url.build( ).toURL( ); 127 | 128 | } catch( MalformedURLException e ) { 129 | throw new PlacesException( e ); 130 | } catch( URISyntaxException e ) { 131 | throw new PlacesException( e ); 132 | } 133 | } 134 | 135 | public PlacesResult searchNearby( float lat, float lon, int radius ) { 136 | return searchNearby( lat, lon, radius, null ); 137 | } 138 | 139 | public PlacesResult searchNearby( float lat, float lon, int radius, PlacesQueryOptions options ) { 140 | try { 141 | URIBuilder url = new URIBuilder( NEARBY_SEARCH_URL ); 142 | url.addParameter( "key", this.apikey ); 143 | url.addParameter( PlacesQueryOptions.LOCATION, lat + "," + lon ); 144 | url.addParameter( PlacesQueryOptions.RADIUS, String.valueOf( radius ) ); 145 | 146 | if ( options != null ) 147 | for ( String param : options.params( ).keySet( ) ) 148 | url.addParameter( param, options.param( param ) ); 149 | 150 | HttpGet get = new HttpGet( url.build( ) ); 151 | return this.parseSearchResponse( this.client.execute( get ) ); 152 | 153 | } catch( Exception e ) { 154 | throw new PlacesException( e ); 155 | } 156 | } 157 | 158 | public PlacesResult searchNearby( Location location, int radius ) { 159 | return this.searchNearby( location, radius, null ); 160 | } 161 | 162 | public PlacesResult searchNearby( Location location, int radius, PlacesQueryOptions options ) { 163 | return this.searchNearby( location.getLat( ), location.getLng( ), radius, options ); 164 | } 165 | 166 | public PlacesResult searchNearby( String pageToken ) { 167 | 168 | try { 169 | URIBuilder url = new URIBuilder( NEARBY_SEARCH_URL ); 170 | url.addParameter( "key", this.apikey ); 171 | url.addParameter( "pagetoken", pageToken ); 172 | 173 | HttpGet get = new HttpGet( url.build( ) ); 174 | return this.parseSearchResponse( this.client.execute( get ) ); 175 | 176 | } catch( Exception e ) { 177 | throw new PlacesException( e ); 178 | } 179 | } 180 | 181 | public PlacesResult searchText( String query ) { 182 | return searchText( query, null ); 183 | } 184 | 185 | public PlacesResult searchText( String query, PlacesQueryOptions options ) { 186 | 187 | try { 188 | URIBuilder url = new URIBuilder( TEXT_SEARCH_URL ); 189 | url.addParameter( "key", this.apikey ); 190 | url.addParameter( "query", query ); 191 | 192 | if ( options != null ) 193 | for ( String param : options.params( ).keySet( ) ) 194 | url.addParameter( param, options.param( param ) ); 195 | 196 | HttpGet get = new HttpGet( url.build( ) ); 197 | return this.parseSearchResponse( this.client.execute( get ) ); 198 | 199 | } catch( Exception e ) { 200 | throw new PlacesException( e ); 201 | } 202 | 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/MatchedSubstring.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | public class MatchedSubstring { 4 | 5 | private int length; 6 | 7 | private int offset; 8 | 9 | public int getLength( ) { 10 | return this.length; 11 | } 12 | 13 | public int getOffset( ) { 14 | return this.offset; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/OpenPeriod.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | public class OpenPeriod { 4 | 5 | private OpenTime open; 6 | 7 | private OpenTime close; 8 | 9 | public OpenTime getClose( ) { 10 | return this.close; 11 | } 12 | 13 | public OpenTime getOpen( ) { 14 | return this.open; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/OpenTime.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | import java.text.DateFormatSymbols; 4 | 5 | public class OpenTime { 6 | 7 | private int day; 8 | 9 | private String time; 10 | 11 | public int getDay( ) { 12 | return this.day; 13 | } 14 | 15 | public String getLocalizedDay( ) { 16 | DateFormatSymbols symbols = new DateFormatSymbols( ); 17 | return symbols.getWeekdays( )[ this.getDay( ) + 1 ]; 18 | } 19 | 20 | public String getShortLocalizedDay( ) { 21 | DateFormatSymbols symbols = new DateFormatSymbols( ); 22 | return symbols.getShortWeekdays( )[ this.getDay( ) + 1 ]; 23 | } 24 | 25 | public String getTime( ) { 26 | return this.time; 27 | } 28 | 29 | public String toString( ) { 30 | return this.getLocalizedDay( ) + " at " + this.getTime( ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/OpeningHours.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | 6 | public class OpeningHours { 7 | 8 | private boolean openNow; 9 | 10 | private List periods = Collections.emptyList( ); 11 | 12 | public List getPeriods( ) { 13 | return this.periods; 14 | } 15 | 16 | public boolean isOpenNow( ) { 17 | return this.openNow; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/Place.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | import java.util.Collections; 4 | import java.util.Set; 5 | 6 | public class Place { 7 | 8 | public static class Geometry { 9 | 10 | private Location location; 11 | 12 | public Location getLocation( ) { 13 | return this.location; 14 | } 15 | 16 | @Override 17 | public String toString( ) { 18 | return this.getLocation( ).toString( ); 19 | } 20 | 21 | } 22 | 23 | public static class Location { 24 | 25 | private float lat; 26 | 27 | private float lng; 28 | 29 | public float getLat( ) { 30 | return this.lat; 31 | } 32 | 33 | public float getLng( ) { 34 | return this.lng; 35 | } 36 | 37 | @Override 38 | public String toString( ) { 39 | return this.getLat( ) + ", " + this.getLng( ); 40 | } 41 | 42 | } 43 | 44 | private String formattedAddress; 45 | 46 | private Geometry geometry; 47 | 48 | private String icon; 49 | 50 | private String id; 51 | 52 | private String name; 53 | 54 | private String placeId; 55 | 56 | private Float rating; 57 | 58 | private String reference; 59 | 60 | private Set types = Collections.emptySet( ); 61 | 62 | private String url; 63 | 64 | private String vicinity; 65 | 66 | public String getFormattedAddress( ) { 67 | return this.formattedAddress; 68 | } 69 | 70 | public Geometry getGeometry( ) { 71 | return this.geometry; 72 | } 73 | 74 | public String getIcon( ) { 75 | return this.icon; 76 | } 77 | 78 | @Deprecated 79 | public String getId( ) { 80 | return this.id; 81 | } 82 | 83 | public String getName( ) { 84 | return this.name; 85 | } 86 | 87 | public String getPlaceId( ) { 88 | return this.placeId; 89 | } 90 | 91 | public Float getRating( ) { 92 | return this.rating; 93 | } 94 | 95 | @Deprecated 96 | public String getReference( ) { 97 | return this.reference; 98 | } 99 | 100 | public Set getTypes( ) { 101 | return this.types; 102 | } 103 | 104 | public String getUrl( ) { 105 | return this.url; 106 | } 107 | 108 | public String getVicinity( ) { 109 | return this.vicinity; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/PlaceDetail.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | import java.net.URL; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | public class PlaceDetail extends Place { 8 | 9 | private List addressComponents = Collections.emptyList( ); 10 | 11 | private List events = Collections.emptyList( ); 12 | 13 | private String formattedPhoneNumber; 14 | 15 | private String internationalPhoneNumber; 16 | 17 | private OpeningHours openingHours; 18 | 19 | private List photos = Collections.emptyList( ); 20 | 21 | private Integer priceLevel; 22 | 23 | private List reviews = Collections.emptyList( ); 24 | 25 | private Integer utcOffset; 26 | 27 | private URL website; 28 | 29 | public List getAddressComponents( ) { 30 | return this.addressComponents; 31 | } 32 | 33 | public List getEvents( ) { 34 | return this.events; 35 | } 36 | 37 | public String getFormattedPhoneNumber( ) { 38 | return this.formattedPhoneNumber; 39 | } 40 | 41 | public String getInternationalPhoneNumber( ) { 42 | return this.internationalPhoneNumber; 43 | } 44 | 45 | public OpeningHours getOpeningHours( ) { 46 | return this.openingHours; 47 | } 48 | 49 | public List getPhotos( ) { 50 | return this.photos; 51 | } 52 | 53 | public Integer getPriceLevel( ) { 54 | return this.priceLevel; 55 | } 56 | 57 | public List getReviews( ) { 58 | return this.reviews; 59 | } 60 | 61 | public Integer getUtcOffset( ) { 62 | return this.utcOffset; 63 | } 64 | 65 | public URL getWebsite( ) { 66 | return this.website; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/PlaceDetailResult.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | import java.util.List; 4 | 5 | public class PlaceDetailResult extends Result { 6 | 7 | private List htmlAttributions; 8 | 9 | private PlaceDetail result; 10 | 11 | public List getHtmlAttributions( ) { 12 | return this.htmlAttributions; 13 | } 14 | 15 | public PlaceDetail getResult( ) { 16 | return this.result; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/PlaceEvent.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | import java.net.URL; 4 | import java.util.Date; 5 | 6 | public class PlaceEvent { 7 | 8 | private String eventId; 9 | 10 | private long startTime; 11 | 12 | private String summary; 13 | 14 | private URL url; 15 | 16 | public String getEventId( ) { 17 | return this.eventId; 18 | } 19 | 20 | public long getStartTime( ) { 21 | return this.startTime; 22 | } 23 | 24 | public String getSummary( ) { 25 | return this.summary; 26 | } 27 | 28 | public Date getStartTimeAsDate( ) { 29 | return new Date( this.getStartTime( ) ); 30 | } 31 | 32 | public URL getUrl( ) { 33 | return this.url; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/PlacePhoto.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | 6 | public class PlacePhoto { 7 | 8 | private int height; 9 | 10 | private List htmlAttributions = Collections.emptyList( ); 11 | 12 | private String photoReference; 13 | 14 | private int width; 15 | 16 | public int getHeight( ) { 17 | return this.height; 18 | } 19 | 20 | public List getHtmlAttributions( ) { 21 | return this.htmlAttributions; 22 | } 23 | 24 | public String getPhotoReference( ) { 25 | return this.photoReference; 26 | } 27 | 28 | public int getWidth( ) { 29 | return this.width; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/PlacesException.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | public class PlacesException extends RuntimeException { 4 | 5 | private static final long serialVersionUID = -7551318600432160726L; 6 | 7 | public PlacesException( Throwable t ) { 8 | super( t ); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/PlacesQueryOptions.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | import java.util.Collections; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import com.claygregory.api.google.places.Place.Location; 8 | 9 | public class PlacesQueryOptions { 10 | 11 | protected static final String KEYWORD = "keyword"; 12 | 13 | protected static final String LANGUAGE = "language"; 14 | 15 | protected static final String LOCATION = "location"; 16 | 17 | protected static final String NAME = "name"; 18 | 19 | protected static final String RADIUS = "radius"; 20 | 21 | protected static final String SENSOR = "sensor"; 22 | 23 | protected static final String TYPES = "types"; 24 | 25 | private Map params = new HashMap( ); 26 | 27 | public static PlacesQueryOptions create( ) { 28 | return new PlacesQueryOptions( ); 29 | } 30 | 31 | public PlacesQueryOptions keyword( String keyword ) { 32 | return this.param( KEYWORD, keyword ); 33 | } 34 | 35 | public PlacesQueryOptions language( String language ) { 36 | return this.param( LANGUAGE, language ); 37 | } 38 | 39 | public PlacesQueryOptions location( Location location ) { 40 | return this.location( location.getLat( ), location.getLng( ) ); 41 | } 42 | 43 | public PlacesQueryOptions location( float lat, float lon ) { 44 | return this.param( LOCATION, lat + "," + lon ); 45 | } 46 | 47 | public PlacesQueryOptions name( String name ) { 48 | return this.param( NAME, name ); 49 | } 50 | 51 | public String param( String key ) { 52 | return this.params.get( key ); 53 | } 54 | 55 | public PlacesQueryOptions param( String key, String value ) { 56 | this.params.put( key, value ); 57 | return this; 58 | } 59 | 60 | public Map params( ) { 61 | return Collections.unmodifiableMap( this.params ); 62 | } 63 | 64 | public PlacesQueryOptions radius( int radius ) { 65 | return this.param( RADIUS, String.valueOf( radius ) ); 66 | } 67 | 68 | public PlacesQueryOptions sensor( boolean sensor ) { 69 | return this.param( SENSOR, String.valueOf( sensor ) ); 70 | } 71 | 72 | public PlacesQueryOptions types( String... types ) { 73 | StringBuilder typesString = new StringBuilder( ); 74 | for ( String type : types ) { 75 | if ( typesString.length( ) != 0 ) typesString.append( '|' ); 76 | typesString.append(type ); 77 | } 78 | 79 | return this.param( TYPES, typesString.toString( ) ); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/PlacesResult.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | import java.util.Collections; 4 | import java.util.Iterator; 5 | import java.util.List; 6 | 7 | 8 | public class PlacesResult extends Result implements Iterable { 9 | 10 | private String nextPageToken; 11 | 12 | private List results; 13 | 14 | public List asList( ) { 15 | return Collections.unmodifiableList( this.results ); 16 | } 17 | 18 | public String getNextPageToken( ) { 19 | return this.nextPageToken; 20 | } 21 | 22 | @Override 23 | public Iterator iterator( ) { 24 | return this.results.iterator( ); 25 | } 26 | 27 | public int size( ) { 28 | return this.results.size( ); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/Prediction.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | import java.util.List; 4 | import java.util.Set; 5 | 6 | public class Prediction { 7 | 8 | private String description; 9 | 10 | private String id; 11 | 12 | private List matchedSubstrings; 13 | 14 | private String placeId; 15 | 16 | private String reference; 17 | 18 | private List terms; 19 | 20 | private Set types; 21 | 22 | public String getDescription( ) { 23 | return this.description; 24 | } 25 | 26 | @Deprecated 27 | public String getId( ) { 28 | return this.id; 29 | } 30 | 31 | public List getMatchedSubstrings( ) { 32 | return this.matchedSubstrings; 33 | } 34 | 35 | public String getPlaceId( ) { 36 | return this.placeId; 37 | } 38 | 39 | @Deprecated 40 | public String getReference( ) { 41 | return this.reference; 42 | } 43 | 44 | public List getTerms( ) { 45 | return this.terms; 46 | } 47 | 48 | public Set getTypes( ) { 49 | return this.types; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/Result.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | public class Result { 4 | 5 | private static final String OKAY_STATUS = "OK"; 6 | 7 | private String status; 8 | 9 | public String getStatus( ) { 10 | return this.status; 11 | } 12 | 13 | public boolean isOkay( ) { 14 | return OKAY_STATUS.equals( this.getStatus( ) ); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/Review.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | import java.net.URL; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | public class Review { 8 | 9 | private List aspects; 10 | 11 | private String authorName; 12 | 13 | private URL authorUrl; 14 | 15 | private String text; 16 | 17 | private long time; 18 | 19 | public List getAspects( ) { 20 | return this.aspects; 21 | } 22 | 23 | public String getAuthorName( ) { 24 | return this.authorName; 25 | } 26 | 27 | public URL getAuthorUrl( ) { 28 | return this.authorUrl; 29 | } 30 | 31 | public String getText( ) { 32 | return this.text; 33 | } 34 | 35 | public long getTime( ) { 36 | return this.time; 37 | } 38 | 39 | public Date getTimeAsDate( ) { 40 | return new Date( this.getTime( ) ); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/claygregory/api/google/places/Term.java: -------------------------------------------------------------------------------- 1 | package com.claygregory.api.google.places; 2 | 3 | public class Term { 4 | 5 | private int offset; 6 | 7 | private String value; 8 | 9 | public int getOffset( ) { 10 | return this.offset; 11 | } 12 | 13 | public String getValue( ) { 14 | return this.value; 15 | } 16 | 17 | @Override 18 | public String toString( ) { 19 | return this.value; 20 | } 21 | } 22 | --------------------------------------------------------------------------------