Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

XML auslesen | PHP & Google Maps API

Empfohlene Antworten

Veröffentlicht

Moin,

ich möchte über die Google API das Bundesland herausfinden. Über die Google APUI Anfrage erhalte ich auch eine "schöne" XML Stuktur zurück:

Ein Beispielaufruf

Wie Du hier sehen kannst, ist das Bundesland in einer der <address_component> gespeichert. Das Problem ist, dass die Anzahl der <address_component> nicht immer gleich ist.

Wenn ich also z.B. mit

$xml->result->address_component[2]->long_name;

auf ein Objekt zugreifen will, zeigt er mir manchmal das Bundesland, manchmal das Land u.s.w., da ich ja jedes mal auf das 2te Objekt zugreife.

Hast Du vielleicht einen Tipp wie ich meine Abfrage besser gestalten kann?

Mit XQuery und XPath kannst du nach den types suchen und dir das Element zurückgeben lassen, dass du suchst.

Du suchst also ein address_component, der ein Kind type mit dem political und ein Kind mit dem type administrative_area_level_1 hat. Von diesem Element wählst du das Kind long_name aus.

  • Autor

Vielen Dank. Das ist genau das was ich suche. Nach dem ersten Blick scheint mir das aber dann doch etwas komplizierter zu sein als erhofft :-/

Aber gut, da muss der Herr wohl durch. Danke Dir!

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.