Google maps returns non english address [duplicate] - java

I have this code for requesting google to correct the typed in address, and need it to return the English name for the city:
function gmap_query_xml($in_address) {
$base_url = "http://maps.google.com/maps/geo?output=xml&region=US&language=en&key=". KEY;
$request_url = $base_url . "&q=" . urlencode($in_address);
return simplexml_load_file($request_url);
}
Then,
$xml = gmap_query_xml($in_address);
And finally to get the city name:
if ($xml) {
$city = (string) $xml->Response->Placemark->AddressDetails->Country->AdministrativeArea->SubAdministrativeArea->Locality->LocalityName;
}
This returns the correct city name, BUT! it's represented in the native language. Try Rome - you get Roma, try Kiev and you will get Киев.
How this can be solved? Thank!!

There seems to be a bit of a chaos in that regard. See this list of Google Geocoding API bug reports.
You are using the old V2 API.
According to this post and my own tests, the new V3 API:
http://maps.google.com/maps/api/geocode/xml?address=Rome&sensor=false&language=en
is more sensitive to the language parameter and translates locality names correctly. I get correct results for language=en (Rome), language=de (Rom) and even language=fi (Rooma)!
However, V3 serves its geocoding results in a different format so you would have to change your parsing considerably (Due to the way addressComponents is structured now, this bugged the heck out of me too).

Related

Creating URL based on an API key in OSRMRoadManager

I've signed up for an API on openrouteservice.org. How do I import it into OSRMRoadManager? I've tried all the combinations from the examples on their website, but my every try results in the 403 error with a comment org.json.JSONException: No value for code and a link to the following:
{
"error": "Daily quota reached or API key unauthorized"
}
(I haven't used that API before, so I couldn't have used up the quota. The key is valid, as I have tested it with the links from the aforementioned website)
My Kotlin code (in my most recent attempt) is as following ([MY_API_KEY] is obviously replacing my real key):
val roadManager = OSRMRoadManager(context, context?.packageName)
(roadManager as OSRMRoadManager).setService("https://api.openrouteservice.org/v2/directions/driving-car/geojson?api_key=[MY_API_KEY]")
val waypoints = ArrayList<GeoPoint>()
waypoints.add(GeoPoint(lastLocLat, lastLocLong)) //last known location
val endPoint = GeoPoint(randomOverlay.getItem(0).point.latitude, randomOverlay.getItem(0).point.longitude) //destination
waypoints.add(endPoint)
val road = roadManager.getRoad(waypoints)
My guess is that the waypoint coordinates should be included differently in the link, but I don't know how to alter that.
openrouteservice directions format is not identical to OSRM, so you cannot use OSRMRoadManager.
If you really - really - want to use openrouteservice, you will have to develop corresponding openrouteserviceRoadManager.
Alternative: use one among the 3 routing services already accessible with OBP. Pros and cons here.

financequotes API returning null values

I have downloaded an API called "financequotes" for Java (Link: http://financequotes-api.com/) and have attempted to use it for a project. It has been imported into my class path and all the methods run, however when I ask for a stocks details
Stock s = new Stock("INTC");
s.print();
I am given back all the details which should have been obtained online as null including name, currency, quote, etc.
Why is this?
ALTERNATIVELY - Could you suggest another finance API which is relatively simple to use to gather basic financial data?
Thanks
The creator of the API has answered - Here was the problem
The code doesn't have a request to Yahoo Finance yet. There's 2 alternative ways to fix this.
Request it through the YahooFinance static methods
Stock stock = YahooFinance.get("INTC");
stock.print();
Force a refresh of the stock's quote by using the getQuote(boolean refresh) method
Stock stock = new Stock("INTC");
stock.getQuote(true);
stock.print();
This will automatically also load/refresh the statistics and dividend data.
Intrinio provides a simple to use API for financial information. It looks like you are a Java user, there are packages on for connecting via rest API and for connecting to real time prices via websocket.
The API is easy to use for stock prices, fundamentals, options, analyst estimates, etc. This tutorial will get you started, but here is an example in curl:
curl "https://api.intrinio.com/prices?ticker=AAPL" -u "API_Password:API_Username"

Box API Java SDK search function is returning limited no. of files

When I am trying to search some term from JAVA sdk of BOX API , I am getting only 400 Results while when i search the same term on app.box.com i am getting 1270 results.
Please help regarding this .
BoxAPIConnection api = new BoxAPIConnection("developer token");
BoxFolder rootFolder = BoxFolder.getRootFolder(api);
Iterable<BoxItem.Info> results = rootFolder.search("*.pdf");
for (BoxItem.Info result : results) {
System.out.println("Result:"+i+" FileName&ID:"+result.getName()+" "+result.getID());
//Only Returning 400 Results
}
There is no limit in the Java SDK for Box API with regards to how many items will be returned. The Iterable<BoxItem.Info> returned by BoxFolder.search() will iterate until the Box API returns no more results (in batches of 200 items).
Therefore, except if you are hitting some sort of an error in the communication with the Box API (use Charles Proxy or Fiddler or similar tool to monitor that), it means that you are hitting a scope issue. A possible explanation would be that when you search at box.com you search in enterprise scope, while when you search via the API you search in user scope. Can you check the results for that?

Retrieve tweets language or filter by language with TwitterStream

I would like to retrieve or filter by language using TwitterStream class. I want to get only tweets of one language or otherwise retrieve everything and then identify each tweet language.
I have build this code but getIsoLanguageCode() returns null always (see version 3.0.4 JavaDocs). I think they have problems with this method.
TwitterStream twitterStream = TwitterPrintRandomStream.createTwitterConnection();
StatusListener listener = new StatusListener() {
public void onStatus(Status status) {
String tw = status.getText() + " " + status.getIsoLanguageCode();
System.out.println(tw);
}
...
}
I also tried the method Status.getUser().getLang() but it returns the user's language not the tweet. Is there any way to do it?
Thanks in advance.
I don't think you can rely on iso_language_code - I couldn't find reference to it in the REST or streaming APIs.
Tweets do have a lang attribute which indicates the language that the Tweet was written in. This was recently added to the API and, unfortunately, Twitter4J does not yet provide you with access to it.
There is a task to add it in version 3.0.4 but the work does not to appear to have started yet. Unfortunately you'll need to wait until they add it or perhaps you could give them a hand and submit a pull-request.
status.getPlace().getCountryCode() should do the trick to get ISO 3166-1 alpha 2 country code
First, Try to get status.getLang() and put em into String then compare it with status.getText() if match you can get the tweets that only contain language in status.getLang()
You can try this following code
String filterTweet=null
String language= status.getLang()
String filterLang="(language code)"
If (filterLang.Matches(language)){
filterTweet=status.getText()}
Cya

how to use google Geocoding in java?

I am developing a functionality for my project that when user enters 'Postal Code' the co-ordinates(latitude, longitude) for the corresponding 'postal code' should display. the implementation platform is 'JAVA'.
I googled for the java api but i did not find any specific resource.
Any suggstions will be greatly appriciated
You can (now) check out the open-source Java client library for Geocoding, Directions, DistanceMatrix, Elevation and TimeZone too: https://github.com/googlemaps/google-maps-services-java
It's quite straight forward. E.g. have a look at the geocode method of this class. Pass your postalcode (along with the country) to the method and you should be fine. (The GLatLng class can be found here but should be replaced by you according to your needs.)
[edit]
I just saw that this example is still using Google Maps v2, but it should be a breeze to convert it to v3.
In the linked documents you can also find the restrictions regarding the use of this service (paragraph "Usage Limits")
You could try to write a REST client (using e.g. Apache HttpClient) for Google geocoding API RESTful web service.
The docs on this are not new user friendly. For me the java docs worked best although theyre quite rigid: https://www.javadoc.io/doc/com.google.maps/google-maps-services/latest/com/google/maps/GeocodingApiRequest.html
Here is how to do so using the newest Google Geocoding API:
//use your google api key to create a GeoApiContext instance
GeoApiContext context = new GeoApiContext.Builder().apiKey("xxxxxx").build();
//this will get geolocation details via zip
GeocodingResult[]results = GeocodingApi.newRequest(context).components(ComponentFiler.postalCode("75002")).await();
System.out.println(results[0]);
//this will get geolocation details via address
GeocodingResult[] results2 = GeocodingApi.geocode(context, "One Apple Park Way Cupertino, CA 95014").await();
System.out.println(results2[0]);
//another way to get geolocation details via address
GeocodingResult[] results3 = GeocodingApi.newRequest(context).address("One Apple Park Way Cupertino, CA 95014").await();
System.out.println(results3[0]);
//geolocation details via lat lng
GeocodingResult[] results4 = GeocodingApi.newRequest(context).latlng(latLng).await();
System.out.println(results4[0]);
from there you'll get a bunch of data on the returned location in the results array, you can parse it as you wish to extract your choice of data. heres an ex of what that data looks like....
[GeocodingResult placeId=ChIJyTSQVXm0j4ARmdUQoA1BpwQ [Geometry: 37.31317000,-122.07238160 (APPROXIMATE) bounds=[37.34159500,-121.99557710, 37.24799500,-122.14382300], viewport=[37.34159500,-121.99557710, 37.24799500,-122.14382300]], formattedAddress=MONTE VISTA, CA 95014, USA, types=[postal_code], addressComponents=[[AddressComponent: "95014" ("95014") (postal_code)], [AddressComponent: "MONTE VISTA" ("MONTE VISTA") (locality, political)], [AddressComponent: "Santa Clara County" ("Santa Clara County") (administrative_area_level_2, political)], [AddressComponent: "California" ("CA") (administrative_area_level_1, political)], [AddressComponent: "United States" ("US") (country, political)]], postcodeLocalities=[Cupertino, MONTE VISTA, Permanente]]
Here is a way for doing it (include source):
http://halexv.blogspot.mx/2015/07/java-geocoding-using-google-maps-api.html
The blog explain how to do it without having and API_KEY and a way for filtering the locatiotions into the most probable one.
Give it a try.

Categories