GumGum Auspuff: Anfänger - GEOCoding mit Google Maps API

Beitrag lesen

Hallo,

wir haben heute im Informatikunterricht die Aufgabe bekommen mit PHP und der Google Maps API zu einer Adresse eine GEO Coordinate zu erstellen.

Ich habe den Testeinwandfrei hinbekommen. Und probiere mich jetzt gerade durch. Gewählt habe ich die Ausgabe von der Google Maps API via XML.
Leider verstehe ich nicht wie ich auf die "address_component" zugreifen kann.
Nehmen wir folgenden Datensatz:

(  
    [status] => OK  
    [result] => SimpleXMLElement Object  
        (  
            [type] => route  
            [formatted_address] => Ackerstraße, 10115 Berlin, Deutschland  
            [address_component] => Array  
                (  
                    [0] => SimpleXMLElement Object  
                        (  
                            [long_name] => Ackerstraße  
                            [short_name] => Ackerstraße  
                            [type] => route  
                        )  
  
                    [1] => SimpleXMLElement Object  
                        (  
                            [long_name] => Mitte  
                            [short_name] => Mitte  
                            [type] => Array  
                                (  
                                    [0] => sublocality  
                                    [1] => political  
                                )  
  
                        )  
  
                    [2] => SimpleXMLElement Object  
                        (  
                            [long_name] => Berlin  
                            [short_name] => Berlin  
                            [type] => Array  
                                (  
                                    [0] => locality  
                                    [1] => political  
                                )  
  
                        )  
  
                    [3] => SimpleXMLElement Object  
                        (  
                            [long_name] => Berlin  
                            [short_name] => Berlin  
                            [type] => Array  
                                (  
                                    [0] => administrative_area_level_1  
                                    [1] => political  
                                )  
  
                        )  
  
                    [4] => SimpleXMLElement Object  
                        (  
                            [long_name] => Deutschland  
                            [short_name] => DE  
                            [type] => Array  
                                (  
                                    [0] => country  
                                    [1] => political  
                                )  
  
                        )  
  
                    [5] => SimpleXMLElement Object  
                        (  
                            [long_name] => 10115  
                            [short_name] => 10115  
                            [type] => postal_code  
                        )  
  
                )

Hier kann ich mit
$xml->result->formatted_address;
die Adresse holen. Soweit verstanden. Somit müssten wir ja bei  print_r($xml->result->address_component);
alle folgenden im Array vorhanden Inhalte angezeigt werden. Dem ist aber nicht so ich sehe nur

SimpleXMLElement Object  
(  
    [long_name] => Ackerstraße  
    [short_name] => Ackerstraße  
    [type] => route  
)

Mache ich aber einen Count auf das Array also count($xml->result->address_component)

Bekomme ich die Zahl 6 ?

Ich verstehe das nicht! Bitte helft mir.