windy1 / google-places-api-java Goto Github PK
View Code? Open in Web Editor NEWComprehensive and FULL Java client for the Google Places API
License: MIT License
Comprehensive and FULL Java client for the Google Places API
License: MIT License
The current tests are rather old and antiquated and have been patched up from old versions of the library and never truly re-fashioned properly. The old tests should be re-written entirely.
Hi,
Can you upload the latest version to maven repository? The one in maven (version 2.1.2) has some issue #35 .
I get a list of suggestion from the AutoComplete api, but now i need to get the latlng for those suggestion. So how do I hit the api with the placeId
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJN1t_tDeuEmsRUsoyG83frY4&key=
Walker, I checked out your code, and when I built it locally I noticed your Places API key has been checked in. I would remove that and either mock out the tests you currently have in place or require developers to insert their own API key before building.
I stumble on this error when creating a new google places object.
Hello Guys,
I was wondering if you guys seen this error before. I am trying to integrate this library into my android app. It compiles without any problems but crashes when i run the app. The error is below.
Thanks!
John
Process: com.johamcruz.Balln, PID: 4118
java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/message/BasicLineFormatter; in class Lorg/apache/http/message/BasicLineFormatter; or its superclasses (declaration of 'org.apache.http.message.BasicLineFormatter' appears in /system/framework/ext.jar)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.(DefaultHttpRequestWriterFactory.java:52)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.(DefaultHttpRequestWriterFactory.java:56)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.(DefaultHttpRequestWriterFactory.java:46)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.(ManagedHttpClientConnectionFactory.java:72)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.(ManagedHttpClientConnectionFactory.java:84)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.(ManagedHttpClientConnectionFactory.java:59)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.(PoolingHttpClientConnectionManager.java:493)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.(PoolingHttpClientConnectionManager.java:149)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.(PoolingHttpClientConnectionManager.java:138)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.(PoolingHttpClientConnectionManager.java:114)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:726)
at se.walkercrou.places.DefaultRequestHandler.(DefaultRequestHandler.java:18)
at se.walkercrou.places.DefaultRequestHandler.(DefaultRequestHandler.java:34)
at se.walkercrou.places.GooglePlaces.(GooglePlaces.java:39)
at com.johamcruz.Balln.Activities.NearbyCourtsActivity$1.run(NearbyCourtsActivity.java:45)
at java.lang.Thread.run(Thread.java:818)
02-28 22:31:42.220 4118-4127/com.johamcruz.Balln E/System﹕ Uncaught exception thrown by finalizer
02-28 22:31:42.221 4118-4127/com.johamcruz.Balln E/System﹕ java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.util.concurrent.atomic.AtomicBoolean.compareAndSet(boolean, boolean)' on a null object reference
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.shutdown(PoolingHttpClientConnectionManager.java:349)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.finalize(PoolingHttpClientConnectionManager.java:172)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:190)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:173)
at java.lang.Thread.run(Thread.java:818)
In order to use this project in an Android app, I had these two lines in the gradle script.
implementation 'se.walkercrou:google-places-api-java:2.1.7'
implementation 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
I noticed the following libraries were added because of the two lines above.
Gradle: org.apache.httpcomponents:httpclient:4.3.5@jar
Gradle: org.apache.httpcomponents:httpclient-android:4.3.5.1@jar
Gradle: org.apache.httpcomponents:httpcore:4.3.2@jar
When I compile and run the project, I got this error message.
Program type already present: org.apache.http.ContentTooLongException
The reason is ContentTooLongException class is present in both httpcore 4.3.2 jar and the httpclient-android 4.3.5.1 jar. If you remove httpclient-android, it compiles but ends up with a run-time exception at the BasicLineFormatter. Do you guys have any idea how to solve this issue?
Thank you!
Good morning,
First congratulate you on your work. Good simple and functional API.
A question like I can search for points based on more than one search criteria.
Javascript API allows me to put in the parameter name like this: value1 | valor21valor3.
But using java api (This is my code):
places = client.getNearbyPlaces(location.getLat(), location.getLng(), 5000, Param.name("name").value("baloto|efecty|jamar"), Param.name("rankBy").value("distance"), Param.name("language").value("es"));
It shows an invalid character error.
I hope your collaboration is the only thing missing me to complete my project.
Hi,
I'm trying to use your library in my project and encounters in following issue:
i can't run the function getNearbyPlacesRankedByDistance more then two times.
Here is my function:
public void SearchPlaces(Context ctx)
{
new Thread(new Runnable() {
public void run() {
List<Place> places=null;
try {
Log.i("MyApp", "search started");
places = client.getNearbyPlacesRankedByDistance(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude(), 20, Param.name("keyword").value(task_category.getSearchKey()));
Log.i("MyApp", "places received");
} catch (Exception e) {
Log.i("MyApp", "exception");
}
Log.i("MyApp", "thread exit");
}
}).start();
}
On the third run i'm running my function, the function getNearbyPlacesRankedByDistance does not returns and seems to be blocked.
After the function execution i don't get anything neither in the log, nor in debug.
What am i doing wrong ?
Regards,
Alex.
I'm not seeing an Api for the Google Detail query - getPlacesByQuery is a text search and does not bring back address components.
I get the following error
Exception in thread "main" se.walkercrou.places.exception.GooglePlacesException: java.io.IOException: javax.net.ssl.SSLPeerUnverifiedException: Host name 'maps.googleapis.com' does not match the certificate subject provided by the peer (CN=*.storage.googleapis.com, O=Google Inc, L=Mountain View, ST=California, C=US)
with the following invocation
GooglePlaces client = new GooglePlaces(googleApiKey);
List<Prediction> predictions = client.getPlacePredictions(location);
If I manually do a HTTPS connection, I encounter no problems. I'd appreciate any suggestions you have.
Error: https://gist.github.com/rohandalvi/3163b833f9f4840066e2
Link to code: https://gist.github.com/rohandalvi/cbe7de2cd3748c6a5a75
Project Gradle file: https://gist.github.com/rohandalvi/9e5fe0c7328f4329a103
App Gradle file: https://gist.github.com/044b0e636aa6a4f17eed
Hi, I'm currently trying to get the details of a list of Places in Paris. The first iteration works fine but the second get stuck on getDetails().
List<Place> places = client.getNearbyPlaces(48.927597, 2.263365, 10, GooglePlaces.MAXIMUM_RESULTS);
for (Place place : places) {
System.out.println("Name: " + place.getName());
Place detail = place.getDetails();
System.out.println("ID: " + detail.getPlaceId());
}
EDIT : I tried to create my own RequestHandler extending your DefaultRequestHandler and replaced the HttpClient. You provide exactly the same thing as HttpClients.getDefault()
and I replaced it with HttpClients.getMinimal()
and it works like a charm.
private final HttpClient client = HttpClients.createMinimal();
I am not at all expert in this, I don't get why your way doesn't work and mine does. Would you please explain to me what the issue is ?
GooglePlaces client = new GooglePlaces("AIzaSyBCrma-NlTle8p1_bE5UqR4CxZWO77ct84");
List<Place> places = client.getNearbyPlaces(38.897676,-77.036530 ,10000, 100);
Hello,
please qny help on why i may be getting places results without additional info suh as place name, vicinity? here is my log:
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? "html_attributions" : [],
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? "results" : [
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? {
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? "geometry" : {
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? "location" : {
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? "lat" : 4.038973,
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? "lng" : 9.687594000000001
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? }
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? },
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? "id" : "eaafbd8ca32a4743e129e0c17235922bc844b79f",
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? "place_id" : "ChIJj-qFruUSYRARPP70h_QEAB8",
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? "reference" : "CpQBhQAAAKUVrAEZIlB_IFn8NneJlFMR_TdS0qb1GaZ85UQKgDdlK90rWXadD8juwERek0wFH0Ps2F739Vxylzwqxo4anI5qZJStP3T4W9V4DNdVdyULwebvjKKHTf1WNW-GLEjtXle_Z4KeKpB75FTgJJhDKEUnp1h5HghYeV0u0BSG6l0UnCElMsZ-THRWujF5wARNXBIQ2dl37vqy2f-H3TxCxQ6oChoUxPMRcvBbibfS0rG8lfbzYKJiklk"
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? },
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? {
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? "geometry" : {
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? "location" : {
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? "lat" : 4.0678,
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? "lng" : 9.7127
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? }
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? },
06-27 09:30:59.307 18330-18705/com.izigate.trackr I/System.out? "id" : "b42b1901de55e63d3574f8660743e1bec57c5f01",
06-27 09:30:59.308 18330-18705/com.izigate.trackr I/System.out? "place_id" : "ChIJ6Y_YDXISYRARlzP7hiv2CSA",
06-27 09:30:59.308 18330-18705/com.izigate.trackr I/System.out? "reference" : "CnRnAAAAdPEjkvuJK5pLaF5rn9871tYe4hamTLK8q5KDDBTqXIEM_kFlFpq3tToBI43PoXY1VBAxJS8yOEm9P3kWvZWbjITPLsPM-anI6cAo_B9LvBwYu8sdLlHLdPrGY_TtUfzkufUTbGxA5FZuI0XzLH3-8BIQMJ0mas9tyfBOHrE8oIDG9RoUz2SYIjZeJoxG28aZXEKmZ8UW2Bc"
06-27 09:30:59.308 18330-18705/com.izigate.trackr I/System.out? },
06-27 09:30:59.308 18330-18705/com.izigate.trackr I/System.out? {
06-27 09:30:59.308 18330-18705/com.izigate.trackr I/System.out? "geometry" : {
06-27 09:30:59.308 18330-18705/com.izigate.trackr I/System.out? "location" : {
06-27 09:30:59.308 18330-18705/com.izigate.trackr I/System.out? "lat" : 4.081312,
06-27 09:30:59.308 18330-18705/com.izigate.trackr I/System.out? "lng" : 9.719552999999999
06-27 09:30:59.308 18330-18705/com.izigate.trackr I/System.out? }
Hey Thanks for the library!
Can you add the function to getNearbyPlaces with rankby. Right now is with radius. I want to show the results based on ranking.
trying to create the subclass but due to buildUrl is private method unable to do that. I am using jar file
Thanks
Hi,
The request seems wrong when using the french language.
The latitude/longitude fields are changed :
46.12345 --> 46,12345
I've created a pull request to fix that.
#23
Cheers,
Hey Windy,
I hope this is not a stupid question. Thank you in advance for any help. I have tried for a while and am unable to figure one part out.
I have your library working and querying places. I get the response and places back. However, what I cannot figure out how to get is the "permanently_closed" boolean that the full API returns. You can see the boolean I am talking about here https://developers.google.com/places/web-service/details. I cannot see any method that returns this? Any chance you could help me with getting it?
Thank you,
Spencer
It appears like Google has a breaking change where their API does not always return the "scope" field in the API anymore. We first detected this on June 4th and it got much worse on June 24th. ~50% of requests no longer have the "scope" field.
java.lang.IllegalArgumentException: No enum constant se.walkercrou.places.Scope.
This is caused by the following lines converting a null value to an empty string and trying to get the enum value of the empty string.
Hello,
I am trying to get an "unlimited" amount of results out of the getNearbyPlaces()
method, so I give Integer.MAX_VALUE
as limit but I always get 60 results.
I went into the GooglePlaces class and it seems the getPlaces()
method overrides my limit with :
limit = Math.min(limit, MAXIMUM_RESULTS); // max of 60 results possible
But then the number of request that have to be sent is calculated with the new limit :
int pages = (int) Math.ceil(limit / (double) MAXIMUM_PAGE_RESULTS);
So obviously I can never have more than 60 results even though it should be possible.
Does anyone know whether this module works on Google App Engine?
If not, is there anything required to make it work? Thanks!
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
https://developers.google.com/places/webservice/search#PlaceSearchResults
as you can see in the link above, Google requires to show attributions on search results, but the library doesn't have any way to get them.
How to query search autocomplete google place api in only country?
Thank you?
I'm having a lot of trouble to manage dependencies with this library.
Do you guys have any tips for importing the library on Android ?
I can't import the 2.0.1 library in my project.
Using version 2.0.0 or 1.2.8 building is working fine.
This is probably a dependency problem but I can't resolve it.
While building I receive the following error.
Error:Execution failed for task ':xxxxxx:dexSnapshotDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Users/xxxxxx/android-sdk/sdk/build-tools/21.1.2/dx --dex --output /Users/xxxxxx/build/intermediates/dex/snapshot/debug --input-list=/Users/xxxxxx/build/intermediates/tmp/dex/snapshot/debug/inputList.txt
Error Code:
1
Output:
warning: Ignoring InnerClasses attribute for an anonymous inner class
(edu.emory.mathcs.backport.java.util.AbstractMap$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(edu.emory.mathcs.backport.java.util.AbstractMap$2) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(edu.emory.mathcs.backport.java.util.concurrent.helpers.Utils$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(edu.emory.mathcs.backport.java.util.concurrent.helpers.Utils$2) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.processClass(Main.java:704)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access$300(Main.java:83)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
...while parsing org/json/JSONArray.class
1 error; aborting
Function String.format("key=%s&location=%f,%f&rankby=distance", apiKey, lat, lng) is converting values in format (#. ##) to (#, ##).
hello
please if someone can explain me how i get photo of place
i use this fuction
if (!findPlace(client.getNearbyPlaces(TEST_PLACE_LAT, TEST_PLACE_LNG, MAXIMUM_RADIUS,
MAXIMUM_RESULTS, TypeParam.name("types").value(Types.TYPE_BEAUTY_SALON)), TEST_PLACE_NAME))
///
private boolean findPlace(List places, String name) {
boolean found = false;
feedsList = new ArrayList<>();
for (Place place : places) {
Shop item = new Shop();
item.BusinessName = place.getName();
List<Photo> photos = place.getPhotos();
Log.e("photo", "" + photos.size());
InputStream stream = photo.download().getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(stream);
// Photo photos = photos.get(new Random().nextInt(photos.size()));
// InputStream stream = photo.download().getInputStream();
// Bitmap bitmap = BitmapFactory.decodeStream(stream);
//
// Log.e("place_img", BitMapToString(bitmap));
feedsList.add(item);
found = true;
}
return found;
and i get list size zero
what i do wrong ?
Radar search returns 200 results at once but the result is treated like 60 Result per page, therefore only the first 20 places are retrieved.
The Week_day text which the places api has is not being parsed here. Here is a sample of what I am talking about
weekday_text: [
"Monday: 11:00 am – 3:00 pm, 5:00 – 8:00 pm",
"Tuesday: 11:00 am – 3:00 pm, 5:00 – 8:00 pm",
"Wednesday: 11:00 am – 3:00 pm, 5:00 – 8:00 pm",
"Thursday: 11:00 am – 3:00 pm, 5:00 – 8:00 pm",
"Friday: 11:00 am – 9:00 pm",
"Saturday: 12:00 – 9:00 pm",
"Sunday: Closed"
]
This occurs at the detail view. This information is valuable because it includes the am/pm information and this information is already converted to 12 hour time (instead of the 24 hour time that the detail view of google places loves to use) I can do this and submit a PR for you guys to review?
When I add the dependency
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
I get the following error
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_40\bin\java.exe'' finished with non-zero exit value 2
but if I take it out I get a runtime error from the library. Any suggestions?
Thanks!
The client can only return a list of places, right? So how to get the pageToken if there is one?
Hi,
I have a problem with your project.
I have follow your indications, all ok but looping on List when I try to get details about a single Place after first result, there is a problem with concurrent connection using HttpClient 4.3.5.
This is a loop using on List
for (Place place : places) {
if (place.getName().equals(textSearch)) {
if (place != null) {
Place detailedPlace = place.getDetails(); // sends a GET request for more details
The problem that I read in log is this:
12/10/2015 16:38:14 DEBUG PoolingHttpClientConnectionManager:219 - Connection request: [route: {s}->https://maps.googleapis.com:443][total kept alive: 0; route allocated: 2 of 2; total allocated: 2 of 20]
Can you help me?
Thank you
Piè
Hi,
I'm having an issue with the exceptions caught by the API. My problem is that the API catches the exceptions and does not let me choose what to do when they occures.
My application is set to send 150k resquests a day (limited by Google) and write data in an excel file. But when an exception occures and is caught by the API my program just ends and I can't tell the application what to do next, and I'm afraid I will lose the data beacause I can't call HSSFWorkbook.write()
from the Apache POI API.
Would it be possible not to catch some exceptions but to throw them so the developper can handle them ? Mostly those caught by the GooglePlace
class.
Hi,
Getting exception when deploying application into GAE container:
Caused by: java.lang.NoClassDefFoundError: javax.naming.ldap.LdapName is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
at org.apache.http.conn.ssl.AbstractVerifier.extractCNs(AbstractVerifier.java:277)
at org.apache.http.conn.ssl.AbstractVerifier.getCNs(AbstractVerifier.java:265)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:157)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:140)
at org.apache.http.conn.ssl.SSLSocketFactory.verifyHostname(SSLSocketFactory.java:561)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:536)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:403)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at se.walkercrou.places.DefaultRequestHandler.get(DefaultRequestHandler.java:77)
at se.walkercrou.places.GooglePlaces.getPlaces(GooglePlaces.java:844)
at se.walkercrou.places.GooglePlaces.getNearbyPlaces(GooglePlaces.java:397)
Looks like that class javax.naming.ldap.LdapName is not possible to use in GAE container. Is it possible to do something?
Some specifications have changed recently and the old methods have been deprecated and will be removed in June.
At first the problem was with Places API not being enabled on my API key. Actually, API key just had no restriction to API and it was supposed to be working.
While my application was running, i open google developer console, restricted API key to Places API, opened my application, tried geocoding an address and it worked.
Then i restarted an application and tried it again - it didn't work again, as if API key haven't had permissions for Places API:
com.google.maps.errors.RequestDeniedException: This API project is not authorized to use this API.
Then i removed Places API restriction from the key in goodle dev console, all while application still was running from the moment when it failed - i tried it again, and it worked.
I have an issue - do i have to put/remove restrictions on API key every time i reboot an application in order for Java API to work?
While experimenting with the library, I found that on the third getNearbyLocations call the GooglePlaces object hangs the thread. However, if I instead initiate a new GooglePlaces object every 2 calls, the objects work fine.
Here is the code I used to test this. The coordinates were chosen due to the large amount of nearby restaurants. I have found that sameInstanceTest()
hangs after 2 print statements, while multipleInstanceTest()
outputs 5 print statements and exits.
public void multipleInstanceTest(){
GooglePlaces gpl = new GooglePlaces(API_KEYS[0]);
int usages = 0;
double[][] testDoubles = new double[][]{
new double[]{40.7607077,-73.980695},
new double[]{40.7607077,-73.980695},
new double[]{40.7607077,-73.980695},
new double[]{40.7607077,-73.980695},
new double[]{40.7607077,-73.980695}
};
double range = 6000;
for (double[] coords : testDoubles){
List<Place> places = new ArrayList<>();
try {
places = gpl.getNearbyPlaces(coords[0], coords[1],range, 20, Param.name("type").value("food"));
} catch (Exception e){
//Default to 0
}
usages ++;
System.out.printf("Got %d locations at coords %f,%f\n",places.size(),coords[0],coords[1]);
if (usages == 2){
gpl = new GooglePlaces(API_KEYS[0]);
usages = 0;
}
}
}
public void sameIstanceTest(){
GooglePlaces gpl = new GooglePlaces(API_KEYS[0]);
double[][] testDoubles = new double[][]{
new double[]{40.7607077,-73.980695},
new double[]{40.7607077,-73.980695},
new double[]{40.7607077,-73.980695},
new double[]{40.7607077,-73.980695},
new double[]{40.7607077,-73.980695}
};
double range = 6000;
for (double[] coords : testDoubles){
List<Place> places = new ArrayList<>();
try {
places = gpl.getNearbyPlaces(coords[0], coords[1],range, 20, Param.name("type").value("food"));
} catch (Exception e){
}
System.out.printf("Got %d locations at coords %f,%f\n",places.size(),coords[0],coords[1]);
}
}
Hi.I was just checking out the Predictions API and I think that the values for latitude and longitude should be double
and not int
.
There is a bug when generating URL , you should pass the Locale.ENGLISH while formatting it otherwise it will generate the wrong url. In my case I am using arabic locale after debugging it, seems url is wrong.
//Current
private static String buildUrl(String method, String params, Param... extraParams) {
String url = String.format("%s%s/json?%s", API_URL, method, params);
url = addExtraParams(url, extraParams);
url = url.replace(' ', '+');
return url;
}
//Should be Locale.ENGLISH
private static String buildUrl(String method, String params, Param... extraParams) {
String url = String.format(Locale.ENGLISH,"%s%s/json?%s", API_URL, method, params);
url = addExtraParams(url, extraParams);
url = url.replace(' ', '+');
return url;
}
Google Places server side code must have recently changed, because as of yesterday, 8/20/15, HttpClient requests made through DefaultRequestHandler are not automatically released after receiving a response.
The solution is to call HttpMethod.releaseConnection() after the response is returned. I'm opening a pull request to address the issue now.
i have an exception like this - REQUEST_DENIED: "This IP, site or mobile application is not authorized to use this API key."
Issue described by: #9
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.