Ich hole mir von Google Maps die Koordinaten anhand einer Adresse.
Leider funktioniert der Code nicht. Es kommt die Fehlermeldung:
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : Start tag expected, '<' not found in D:\php\... on line 17
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: { in D:\php\... on line 17
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in D:\php\... on line 17
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in D:\php\reinicke\admin\test.php:17 Stack trace: #0 D:\php\...(17): SimpleXMLElement->__construct('{? "name": "Ge...') #1 {main} thrown in D:\php\... on line 17
Wenn ich mit print_r($urlinhalt) abfrage bekomme ich zB sowas:
{ "name": "Germany 71640 Ludwigsburg Corneliusstrasse 31", "Status": { "code": 200, "request": "geocode" }, "Placemark": [ { "id": "p1", "address": "Corneliusstra? 31, 71640 Ludwigsburg, Germany", "AddressDetails": {"Country": {"CountryNameCode": "DE","CountryName": "Germany","AdministrativeArea": {"AdministrativeAreaName": "Baden-W?emberg","SubAdministrativeArea": {"SubAdministrativeAreaName": "Ludwigsburg","Locality": {"LocalityName": "Ludwigsburg","Thoroughfare":{"ThoroughfareNam e": "Corneliusstra? 31"},"PostalCode": {"PostalCodeNumber": "71640"}}}}},"Accuracy": 8}, "Point": { "coordinates": [ 9.2164575, 48.9002927, 0 ] } } ] }
Wie bekomme ich daraus die Koordinaten?
Vielen Dank
Leider funktioniert der Code nicht. Es kommt die Fehlermeldung:
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : Start tag expected, '<' not found in D:\php\... on line 17
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: { in D:\php\... on line 17
Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: ^ in D:\php\... on line 17
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in D:\php\reinicke\admin\test.php:17 Stack trace: #0 D:\php\...(17): SimpleXMLElement->__construct('{? "name": "Ge...') #1 {main} thrown in D:\php\... on line 17
PHP-Code:
// Angabe deines Google Api Keys
$key ="ABC";
//Angabe der Adresse, von der die Koordinaten geholt werden sollen
$adresse="http://maps.google.com/maps/geo?q=Germany+".$_POST["plz"]."+".$_POST["ort"]."+".$_POST["anschrift"]."+".$_POST["hausnummer"]."&output=xml&key=$key";
//XML File von google holen
$urlinhalt=file_get_contents($adresse);
//XML File utf8 konvertieren
$urlinhalt = utf8_decode ($urlinhalt);
print_r($urlinhalt);
/*
//SimpleXMLElement Objekt erstellen
$xml = new SimpleXMLElement($urlinhalt);
//Koordinaten auslesen - trennen - und in 2 variablen speichern
list($longitude, $latitude, $altitude) = explode (",",$xml->Response->Placemark->Point->coordinates);
//Koordinaten ausgeben
echo "Longitude: $longitude, Latitude: $latitude";
{ "name": "Germany 71640 Ludwigsburg Corneliusstrasse 31", "Status": { "code": 200, "request": "geocode" }, "Placemark": [ { "id": "p1", "address": "Corneliusstra? 31, 71640 Ludwigsburg, Germany", "AddressDetails": {"Country": {"CountryNameCode": "DE","CountryName": "Germany","AdministrativeArea": {"AdministrativeAreaName": "Baden-W?emberg","SubAdministrativeArea": {"SubAdministrativeAreaName": "Ludwigsburg","Locality": {"LocalityName": "Ludwigsburg","Thoroughfare":{"ThoroughfareNam e": "Corneliusstra? 31"},"PostalCode": {"PostalCodeNumber": "71640"}}}}},"Accuracy": 8}, "Point": { "coordinates": [ 9.2164575, 48.9002927, 0 ] } } ] }
Wie bekomme ich daraus die Koordinaten?
Vielen Dank
Kommentar