how to use google Geocoding in java? - 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.

Related

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"

How to call solr analysis api in java?

Is there a way to call solrs analysis api in java using solr-core and get the analyzed tokens.
Analysis api takes fieldName or fieldType and values and give the analyzed tokens.
Is there a way to get those tokens from java?
I found the following link: FieldAnalysisRequestHandler, But I could not get any examples to use it.
In the Admin UI (for which the FieldAnalysisRequestHandler is meant) you can call it by selecting a core and then go to the "Analysis" entry.
See https://cwiki.apache.org/confluence/x/UYDxAQ or https://cwiki.apache.org/confluence/x/FoDxAQ for that.
From a client (which I guess you mean, as you tagged this question with solrj) you need to call the correct URL.
Typically the FieldAnalysisRequestHandler is bound to /analysis/field, see your solrconfig.xml.
From Solrj it should work like this:
SolrQuery query = new SolrQuery();
solrQuery.setRequestHandler("/analysis/field");
solrQuery.set("analysis.fieldtype", "mytype");
solrQuery.set("analysis.fieldvalue", "myval");
QueryResponse solrResponse = solrServer.query(solrQuery);
But it doesn't seem like there's a great support for this in Solrj, probably because it's meant to be called from the Solr Admin UI as mentioned.

How to Know Model Type using AWS Java SDK for Machine Learning

I am using AWS Java SDK to generate RealTime Predictions. To get the output of prediction i need to know what kind of machine learning model is being used is it binary , regression or multiclass. I have only the model id which i can use to locate model.Is there any API or some other way through which i can know the model type in my application.
I have searched through the documentation but haven't found anything that suits my requirement.
You can get the model type by calling the GetMLModel API.
AmazonMachineLearningClient client = ...;
GetMLModelRequest request = new GetMLModelRequest().withMLModelId("...");
client.getMLModel(request).getMLModelType();

Google maps returns non english address [duplicate]

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).

Sugar CRM integration with Java - How to add relationship

I'm trying to integrate Sugar CRM with one of my projects. I'm using Apache Axis as my SOAP client.
I've created the Sugar CRM client Stub classes using Apache Axis.
I'm able to login and add Leads, Opportunities, Accounts and Contacts.
But I'm unable to add a relation ship between my Account and Opportunity.
I've found following method in the SugarsoapPortType
port.set_relationship(session, module_name, module_id, link_field_name, related_ids, name_value_list, delete)
but I cannot understand the different parameters required by this method.
Most of the online documents suggests a simple way as given below
$result = $client->call('set_relationship',array("session"=>$session _id,array("module1"=>"Emails","module1_id"=>"<module1_id>","module2"=>"Accounts","module2_id"=> "<module2_id>")));
how can I achieve this using Java
Thanks
Got this after a lot of search
Example
New_set_relationship_list_result relationship = port.set_relationship(sessionID, "Accounts", "<account_id>", "opportunities", new String[] {"<opportunity_id>"}, null, 0);

Categories