Search code examples
javatwittergeolocationtwitter4jbounding-box

twitter4j geo streaming latitude/longitude for Singapore and beyond


Although it might look like the same problem as twitter4j geo streaming latitude/longitude for Hongkong but it isn't.

I have modified the streaming example code from twitter4j and produced this: https://www.dropbox.com/s/gj75fghtqy5jajf/tweity.zip?dl=0

It can be compiled with:

$ javac -classpath twitter4j-core-4.0.4.jar:twitter4j-media-support-4.0.4.jar:twitter4j-async-4.0.4.jar:twitter4j-examples-4.0.4.jar:twitter4j-stream-4.0.4.jar PrintFilterLocationStream.java

And run with:

java -cp .:twitter4j-core-4.0.4.jar:twitter4j-media-support-4.0.4.jar:twitter4j-async-4.0.4.jar:twitter4j-examples-4.0.4.jar:twitter4j-stream-4.0.4.jar PrintFilterLocationStream "{{-126.562500,30.448674},{-61.171875,44.087585}}"

It works perfectly fine if I get the bounding box correct, see Can't get location filters to work using Twitter4J

But for Singapore, I have checked the location from http://isithackday.com/geoplanet-explorer/index.php?woeid=24703045 but somehow it's complaining that it's not valid.

[out]:

[Wed Jul 06 05:48:15 SGT 2016]Parameter not accepted with the role. 406:Returned by the Search API when an invalid format is specified in the request.
Returned by the Streaming API when one or more of the parameters are not suitable for the resource. The track parameter, for example, would throw this error if:
 The track keyword is too long or too short.
 The bounding box specified is invalid.
 No predicates defined for filtered resource, for example, neither track nor follow parameter defined.
 Follow userid cannot be read.
Latitude/longitude are not valid: 1.31, 103.75, 1.47, 103.87

406:Returned by the Search API when an invalid format is specified in the request.
Returned by the Streaming API when one or more of the parameters are not suitable for the resource. The track parameter, for example, would throw this error if:
 The track keyword is too long or too short.
 The bounding box specified is invalid.
 No predicates defined for filtered resource, for example, neither track nor follow parameter defined.
 Follow userid cannot be read.
Latitude/longitude are not valid: 1.31, 103.75, 1.47, 103.87

I have tried a bigger box too ("{{1,103},{2,104}}" for Singapore) but it still not valid.

I have tried using "{{0.66364, 98.935059},{7.58378, 119.448433}}" for Mlaysia according to http://isithackday.com/geoplanet-explorer/index.php?start=malaysia but it's not valid too. Similarly, "{{ -11.00485, 94.969833},{6.07573, 141.021805}}" for Indonesia didn't work too (http://isithackday.com/geoplanet-explorer/index.php?start=indonesia).

  • What should the latitude/longitude value be for Singapore?

  • But what about Malayisa or Indonesia?

  • Is there a list of bounding boxes for countries/cities? It looks like it could easily be a static list?


Solution

  • The coordinates that twitter4j require were in the opposite order as shown on http://isithackday.com/geoplanet-explorer/index.php?start=singapore ...

    For Singapore, it's "{{103.618248,1.1158},{104.40847, 1.47062}}"

    For Malaysia, it's "{{98.935059,0.66364},{119.448433,7.58378}}"

    For Indonesia, it's "{{94.969833,-11.00485},{141.021805,6.07573}}"

    Beyond that, for other locations if http://isithackday.com/geoplanet-explorer/index.php shows:

    Bounding Box:
    NE numA, numB
    SW numC, numD
    

    The twitter4j FilterQuery.locations expects:

    {{numD,numC},{numB,numA}}