gpt4 book ai didi

php - 由于以下原因,地理编码未成功 零结果 - PHP 变量

转载 作者:行者123 更新时间:2023-11-29 07:42:40 24 4
gpt4 key购买 nike

我正在尝试显示调用的地址我的 sql 数据库,我无法显示地址我不断收到此错误“地理编码因以下原因 Zero_Results 未成功”

我尝试在一个变量 $address 中添加完整地址,而不是使用三个变量 $address 、 $county 、 $county 但仍然不行正在工作,但我无法弄清楚。

我想将地址显示为标记,如图所示。

每当我将新地址添加到数据库中时,我都会将新标记添加到 map 中。

enter image description here

任何帮助,

提前致谢。

这是我正在使用的代码:

$result = mysqli_query($con,"SELECT * FROM `test`") or die ("Error:      
".mysqli_error($con));
while ($row = mysqli_fetch_array($result))
{
$address = $row['address'];
$county = $row['County'];
$country = $row['Country'];
}
mysqli_close($con);

<!DOCTYPE html>
<html>
<head>

<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?
key=mykey&sensor=false">

</script>


<script type="text/javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(
53.41291,-8.243889999999965);
var address = '<?php echo $address.', '.$country.', '.$county; ?
>';

var myOptions = {
zoom: 6,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
geocoder.geocode( { 'address': address}, function(results,
status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason:
" + status);
}
});
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:500px; height:500px"></div>

</body>
</html>

最佳答案

我的问题解决了,我的解决方案是:

            <script type="text/javascript">
var geocoder;
var map;
function initialize(address) {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(
53.41291,-8.243889999999965);


var myOptions = {
zoom: 6,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
<?php
require('connection.php');

$result = mysqli_query($con,"SELECT * FROM `test`") or die
("Error: ".mysqli_error($con));
$count = 0;


?>
<?php //Starts while loop so all addresses for the given
// information will be populated.
$addresscounting=0;
while($row = mysqli_fetch_assoc($result)) //instantiates
// array
{ ?>


var address = "<?php echo $address ?>";


geocoder.geocode( { 'address': address}, function(results,
status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason:
" + status);
}
});

<?php
$count++;

} //ends while
?>
}

</script

关于php - 由于以下原因,地理编码未成功 零结果 - PHP 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28604268/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com