Skip to content

Each GooglePlaces Instance Can Only Perform 2 getNearbyLocations Calls #53

@ischeinkman

Description

@ischeinkman

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]);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions