我的问题是标题说我的表行设置是浮点16,11为lat和long 其他是varchar奇怪的是,我回应了价值,这给了我正是我所期待的,但在数据库中显示0,00000000。其他值存储正确的任何建议我在php msql感谢
<?php require_once("includes/myDataBaseConnection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php
//postcode omzetten naar coordinaten
function lookup($string){
$string = str_replace (" ", "+", urlencode($string));
$details_url = "http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:".$string."|country:nl&sensor=false";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $details_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = json_decode(curl_exec($ch), true);
// If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST
if ($response['status'] != 'OK') {
return null;
}
$geometry = $response['results'][0]['geometry'];
$plaats = $response['results'][0]['address_components'][2]['long_name'];
$provincie = $response['results'][0]['address_components'][3]['long_name'];
$longitude = (float)$geometry['location']['lat'];
$latitude = (float)$geometry['location']['lng'];
$mapCor = array(
'latitude' => (float)$geometry['location']['lng'],
'longitude' => (float)$geometry['location']['lat'],
// 'location_type' => $geometry['location_type'],
'plaats' => $response['results'][0]['address_components'][2]['long_name'],
'provincie' => $response['results'][0]['address_components'][3]['long_name']
);
return $mapCor;
}
$postcode = $_POST['postcode'];
$mapCor = lookup($postcode);
//query opslaan
foreach ($mapCor as $key => $value) {
print($value);
$query = "INSERT INTO markers (";
$query .= "lat, lng, address, provincie";
$query .= ") VALUES (";
$query .= " '$value', '$value', '$value', '$value' ";
$query .= ")";
}
$result = mysqli_query($connection, $query);
if ($result) {
print ("succes!");
//redirect_to("testGoogleMaps.php");
} else {
// Failure
print ("Subject creation failed.");
}
if (isset($connection)) { mysqli_close($connection); }
?>`enter code here`
答案 0 :(得分:1)
$mapCor = lookup($postcode);
foreach ($mapCor as $key => $value) {
print($value);
}
$query = '
INSERT INTO markers ( `lat`, `lng`, `address`, `provincie`)
VALUES ( \''.$mapCor['latitude'].'\', \''.$mapCor['longitude'].'\', \''.$mapCor['plaats'].'\', \''.$mapCor['provincie'].'\')
';