I'm using the Javascript Geocoder.
However, according to the documentation found at:
http://code.google.com/apis/maps/documentation/v3/services.html#GeocodingResponses
: "The GeocoderResults object literal is a JSON object ..."
My java code is fairly simple for example's sake, it is:
JAVA SIDE:
~~~~~~~~~
private void handleCallback(String result, String status,
AjaxRequestTarget target) {
JSONDeserializer<GeocodeResult> deser =new
JSONDeserializer<GeocodeResult>();
deser.use( null, GeocodeResult.class );
String fixedResult = fixResult(result);
System.out.println("fixedResult=["+fixedResult+"]");
GeocodeResult resultObject =
deser.deserialize( fixedResult );
System.out.println("at handleCallBack with result: ["+result
+"] and status:["+status+"] and result object: ["+resultObject+"]");
}
private String fixResult(String result) {
return result.replaceAll("(location.*?)\"b\"(.*?)\"c\"",
"$1\"lat\"$2\"lon\"");
}
HTML SIDE:
~~~~~~~~~
function handleResponse(results, status){
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
var myJSONText = JSON.stringify(results[0], null);
wicketCallBack(myJSONText,status);
} else {
alert("Geocode was not successful for the
following reason: " + status);
}
}
NOTES:
~~~~~~
I'm using ajax for moving the data around, my web framework is wicket
(not GWT), running on tomcat with liferay portal, flexJson on the
server side, and json2.js (from jquery) on the client side.
If there's any other data that you need, I'll be happy to provide it!
I understand that you do not provide the json structure for the latlng
and the latlngbounds object, which is kind of the reason for the post
- why not? I'm sure I'm not the only one that's doing this - moving
data from javascript to java and back is kinda the point of json so
the logic of doing it half way eludes me...
e.
On Mar 24, 6:25 pm, Ben Appleton <[email protected]> wrote:
> To be sure, you mean the JavaScript Geocoder
> (http://code.google.com/apis/maps/documentation/v3/services.html#Geoco...)
> not the HTTP Web Service
> (http://code.google.com/apis/maps/documentation/geocoding/index.html) right?
>
> The JavaScript Geocoder does not return JSON, it returns a JavaScript
> Object. For convenience we provide google.maps.LatLng and
> google.maps.LatLngBounds instances where appropriate, not eg. {lat:...,
> lng:...} structs.
>
> What is your Java code - are you using GWT or are you passing the geocode
> result to a Java server?
>
> - Ben
>
>
>
> On Thu, Mar 25, 2010 at 8:29 AM, Sheepz <[email protected]> wrote:
> > Thanks for the answer but if possible, I'd appreciate some more
> > details, I understand that this is not something you consider as a
> > defect, can you please elaborate on why you say that? is there a way
> > to stringify this correctly and I'm just not using it? my workaround
> > at the moment is some search and replace method that runs on the
> > object on the server side but it seems like something is being done
> > wrong, either on my end or in the implementation, so please elaborate
> > in your response.
> > Tia,
> > Elad.
>
> > On Mar 24, 5:12 pm, Ben Appleton <[email protected]> wrote:
> >> This is working as intended.
>
> >> On 25 Mar 2010 08:02, "Sheepz" <[email protected]> wrote:
>
> >> Hi All, I'm using Json to parse the gecode result and pass it to my
> >> java code, where I rebuild it.
> >> This it my JS code for parsing the result to a string:
> >> var myJSONText = JSON.stringify(results[0], null);
> >> it returns the following for a query about Germany:
> >> "[
> >> {
> >> "types":["country","political"],
> >> "formatted_address":"Deutschland",
> >> "address_components":
> >> [{"long_name":"Deutschland","short_name":"DE","types":
> >> ["country","political"]}],
> >> "geometry":{
> >> "location":{"b":51.165691,"c":10.451526},
> >> "location_type":"APPROXIMATE",
> >> "viewport":{"c":{"b":47.4430843,"c":54.6103698},"b":{"d":180,"c":
> >> 2.255725,"b":18.647327}},
> >> "bounds":{"c":{"b":47.270127,"c":55.0815},"b":{"d":180,"c":
> >> 5.8663566,"b":15.0418536}}}}
>
> >> ]"
>
> >> Note the location, viewport and bounds.
> >> These are not proper json objects and are therefore parsed in a way
> >> that cannot be used to reconstruct the object on the java side.
> >> The objects in question are the LatLng and the LatLngBounds objects.
> >> Is this a bug that's going to be fixed soon?
> >> Am i missing something in the way i parse it?
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Google Maps JavaScript API v3" group.
> >> To post to this group, send email to
>
> [email protected].>> To unsubscribe from this group,
> send email to
> >> [email protected]<google-maps-js-api-v3%[email protected]>
>
> <google-maps-js-api-v3%[email protected]<google-maps-js-api-v3%[email protected]>
>
> >> .
> >> For more options, visit this group athttp://
>
> groups.google.com/group/google-maps-js-api-v3?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
>
> "Google Maps JavaScript API v3" group.> To post to this group, send email to
>
> [email protected].> To unsubscribe from this group, send
> email to
>
> [email protected]<google-maps-js-api-v3%[email protected]>
> .> For more options, visit this group at
>
> http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.