Monday, October 29, 2012

External Server communication with HTTP requests

Hello,

I need support for the communication with external services like Google Maps API.
The following code and websites includes my concerns.

At first I want to get a google map with a HTTP request.
The following website shows the information for my intention.

How can I get Google Maps over HTTP requests?

Another point is the geocoding API from google. 
I want to get information with the geoCodeStr.
I tried this string with my browser and get information which you can see under the HTTP request code.
The problem of my project is that I get no response.
The status code is 0.

I hope someone can give me some advice?

Thanks.

String geoCodeStr= URL.encode("http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false");
requestBuilder = new RequestBuilder(RequestBuilder.GET, geoCodeStr);
try {
requestBuilder.sendRequest(null,
new RequestCallback() {
public void onError(Request request, Throwable exception) {
Window.alert("Request timeout or no connection to server: "
+ exception.getMessage());
}

public void onResponseReceived(Request request,
Response response) {
System.out.println(response.getHeadersAsString());
System.out.println(response.getText());
if (200 == response.getStatusCode()) {
System.out.println(response.getText());
} else {
Window.alert(""+response.getStatusText());
}
System.out.println(Integer.toString(response.getStatusCode()));
}
});
} catch (RequestException e) {
Window.alert("No connection with server: "+e.getMessage());
}
}

{     "results" : [        {           "address_components" : [              {                 "long_name" : "1600",                 "short_name" : "1600",                 "types" : [ "street_number" ]              },              {                 "long_name" : "Amphitheatre Pkwy",                 "short_name" : "Amphitheatre Pkwy",                 "types" : [ "route" ]              },
...

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/X_vIMWxc78sJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment