Hello, I have implemented a code to grab the locality, province,
autonomous region and country short name (it is the administrative
division for spain, but I think the code can be helpful for you.
Furthermore it works in most part of european countries, and I think
the locality and country should work everywhere.
getAddress: function(latlng){
if (demo.geolocalizacion.geocoder)
{
demo.geolocalizacion.geocoder.geocode( {'latLng':
latlng},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results) {
demo.geolocalizacion.direcciones = results;
cpais=null;
aut=null;
prov=null;
pob=null;
$.each(results, function(){
if(this.types=='street_address'){
$.each(this.address_components,
function(){
cogerComponentes(this);
});
}
if(this.types=='postal_code'){
$.each(this.address_components, function(){
cogerComponentes(this);
});
}
if(this.types=='locality,political'){
$.each(this.address_components,
function(){
cogerComponentes(this);
});
}
if(this.types=='administrative_area_level_2,political'){
$.each(this.address_components,
function(){
cogerComponentes(this);
});
}if(this.types=='administrative_area_level_1,political'){
$.each(this.address_components,
function(){
cogerComponentes(this);
});
}
if(this.types=='country,political'){
$.each(this.address_components,
function(){
cogerComponentes(this);
});
}
})
}
} else {
$('#errors').html('<p><strong>Error:</strong> Geocoder failed
due to: ' + status + '</p>').slideDown();
}
});
}
}
function cogerComponentes(esto){
if(esto.types=='locality,political'&&pob==null)
pob=esto.long_name;
if(esto.types=='administrative_area_level_2,political'&&prov==null)
prov=esto.long_name;
if(esto.types=='administrative_area_level_1,political'&&aut==null)
aut=esto.long_name;
if(esto.types=='country,political'&&cpais==null)
cpais=esto.short_name;
}
you should ignore the prov and aut code, and change
cpais=esto.short_name; for cpais=esto.long_name;
On 6 jun, 16:22, FLX <[email protected]> wrote:
> Hello,
>
> example:http://pastebin.com/qFj1SGsg
> I'm currently using formatted_address but I'm trying to get just city
> and country in to two separate variables.
> I've been trying all kinds of ways but it appears my JSON skills suck.
> I can do a regular expression to grab the info I need but that would
> be a very dirty solution, there must be a better way, can anybody lend
> me a hand?
>
> Thank you in advance,
>
> Dennis
--
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.