Install
Legacy Member
ik ben mij een beetje aan het verdiepen in de google maps API
nu heb ik een scriptje gemaakt dat adressen uti een database haalt , de gps coordinaten ophaalt en ze daarna plaatst op een map.
Dit systeem werkt op 1 foutje na , hij kan geen "vreemde" karakters lezen.
de error die ik krijg
hij kan de ringel S niet lezen blijkbaar.
Hoe kan ik dit in godsnaam oplossen?
volledige php code :
nu heb ik een scriptje gemaakt dat adressen uti een database haalt , de gps coordinaten ophaalt en ze daarna plaatst op een map.
Dit systeem werkt op 1 foutje na , hij kan geen "vreemde" karakters lezen.
de error die ik krijg
PHP:
Warning: simplexml_load_file() [function.simplexml-load-file]: http://maps.google.com/maps/geo?output=xml&key=*****&q=Krumme+Str.+48%2C+Berlin:9: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xDF 0x65 0x20 0x34 in H:\usbw\Root\index.php on line 51
Warning: simplexml_load_file() [function.simplexml-load-file]: <address>Krumme Straße 48, 10627 Berlin, Germany</address> in H:\usbw\Root\index.php on line 51
Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in H:\usbw\Root\index.php on line 51
url not loading
Hoe kan ik dit in godsnaam oplossen?
volledige php code :
PHP:
require("log.php");
function fixEncoding($in_str)
{
$cur_encoding = mb_detect_encoding($in_str) ;
if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8"))
return $in_str;
else
return utf8_encode($in_str);
}
define("MAPS_HOST", "maps.google.com");
define("KEY", "ABQIAAAAo6mpRmLt7BfksxYYdiZ8rBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxRSs7mMs2ZFVX01EBISGJdFLMaYFQ");
// Opens a connection to a MySQL server
$connection = mysql_connect("localhost", $username, $password);
if (!$connection) {
die("Not connected : " . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die("Can\'t use db : " . mysql_error());
}
// Select all the rows in the markers table
mysql_query("SET * utf8");
$query = "SELECT * FROM locations WHERE 1";
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
// Initialize delay in geocode speed
$delay = 0;
$base_url = "http://" . MAPS_HOST . "/maps/geo?output=xml" . "&key=" . KEY;
// Iterate through the rows, geocoding each address
while ($row = @mysql_fetch_assoc($result)) {
$geocode_pending = true;
while ($geocode_pending) {
$address = $row["pAdress"];
$id = $row["id"];
$request_url = $base_url . "&q=" . urlencode($address);
$xml = simplexml_load_file($request_url) or die("url not loading");
$status = $xml->Response->Status->code;
if (strcmp($status, "200") == 0) {
// Successful geocode
$geocode_pending = false;
$coordinates = $xml->Response->Placemark->Point->coordinates;
$coordinatesSplit = split(",", $coordinates);
// Format: Longitude, Latitude, Altitude
$lat = $coordinatesSplit[1];
$lng = $coordinatesSplit[0];
$query = sprintf("UPDATE locations " .
" SET pLat = '%s', pLng = '%s' " .
" WHERE id = '%s' LIMIT 1;",
mysql_real_escape_string($lat),
mysql_real_escape_string($lng),
mysql_real_escape_string($id));
$update_result = mysql_query($query);
if (!$update_result) {
die("Invalid query: " . mysql_error());
}
} else if (strcmp($status, "620") == 0) {
// sent geocodes too fast
$delay += 100000;
} else {
// failure to geocode
$geocode_pending = false;
echo "Address " . $address . " failed to geocoded. ";
echo "Received status " . $status . "
\n";
}
usleep($delay);
}
}
?>
