我试图在我的传单地图上显示一个标记。这给了我以下错误:TypeError: t is null
使用 Google Maps API 获取坐标的 PHP 代码:
<?php
if (isset($_POST["checkAddress"])) { //Checks if action value exists
$checkAddress = $_POST["checkAddress"];
$plus = str_replace(" ", "+", $checkAddress);
$json = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=' . $plus . '&key=KEY');
$obj = json_decode($json);
$mapLat = $obj->results[0]->geometry->location->lat;
$mapLng = $obj->results[0]->geometry->location->lng;
$coords = ('' . $mapLat . ', ' . $mapLng . '');
echo $coords;
}
?>
Run Code Online (Sandbox Code Playgroud)
jQuery 运行 PHP 脚本并应在 Leaflet 地图上显示坐标:
$(document).ready(function() {
$("#button").click(function(){
$.ajax({
url: "geo.php",
method: "POST",
data: {
checkAddress: $("#largetxt").val()
}, …Run Code Online (Sandbox Code Playgroud)