Autor |
Nachricht |
zweitaccount
Threadersteller
Dabei seit: 25.01.2008
Ort: -
Alter: -
Geschlecht: -
|
Verfasst Fr 20.05.2011 14:48
Titel Google Maps V3 adress_components result auflösen |
|
|
Hi, ich versuche über den Google Geocoder den Standort
des Users aufzulösen. Funzt ja auch soweit, nur frage ich
mich ob die reihenfolge des address_components-array
auch immer gleich bleibt - oder es sich je nach Ergebnis
ändern kann? Also ob z.B. [0] wirklich immer die Street ist?
Code: | _geocoder.geocode({'location': _mapInitialLocation}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var street = results[0].address_components[0].long_name;
var cityRegion = results[0].address_components[1].long_name;
var city = results[0].address_components[2].long_name;
var cityAgain = results[0].address_components[3].long_name; // ?hä
var region = results[0].address_components[4].long_name;
var country = results[0].address_components[5].long_name;
_elGoogleMapAddress.value = city + ', ' + country;
}
}); |
Find nix in der Docu
|
|
|
|
|
choise
Dabei seit: 01.02.2007
Ort: Würzburg
Alter: 35
Geschlecht:
|
Verfasst Fr 20.05.2011 15:01
Titel
|
|
|
nein, da kommt es drauf an wie genau deine suchanfrage ist.
wenn zb nur nach einer stadt gesucht wird, dann ist im array als erstes die stadt und eine straße taucht gar nicht auf.
in dem Array gibt es immer noch ein "types" welches angibt was genau sich darin befindet.
|
|
|
|
|
Anzeige
|
|
|
zweitaccount
Threadersteller
Dabei seit: 25.01.2008
Ort: -
Alter: -
Geschlecht: -
|
Verfasst Fr 20.05.2011 15:04
Titel
|
|
|
Ah ja, Suchanfrage ists ja praktisch nicht, das geht ja über
navigator.geolocation oder google.gears (wenn da).
Aber danke für den types-Tipp, das hat mir auf die Sprünge geholfen.
Falls jemand ähnliches sucht:
Code: | _geocoder.geocode({'location': _mapInitialLocation}, function(results, status) {
var locationType = null;
var locationCity = null;
var locationCountry = null;
for (var i = 0; i < results[0].address_components.length; i++) {
locationType = results[0].address_components[i].types;
if (locationType.contains('country')) {
//alert('found Country:' + results[0].address_components[i].long_name);
locationCountry = results[0].address_components[i].long_name;
} else if (locationType.contains('locality')) {
//alert('found City:' + results[0].address_components[i].long_name);
locationCity = results[0].address_components[i].long_name;
} else {
//alert(types + '|' + results[0].address_components[i].long_name);
}
if (locationCity && locationCountry) {
_elGoogleMapAddress.value = locationCity + ', ' + locationCountry;
break;
}
}
}); |
Greez
|
|
|
|
|
|
|
|
Ähnliche Themen |
Google Kontakte auf Google Maps auslesen/anzeigen lassen
Google Maps und Google Places
Google Maps API
GOOGLE MAPS`?
Google Maps API
Google Maps-API
|
|