小编TJ *_*J W的帖子

Leaflet 不会显示我的标记,“TypeError: t is null”

我试图在我的传单地图上显示一个标记。这给了我以下错误: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)

javascript php jquery coordinates leaflet

3
推荐指数
1
解决办法
6045
查看次数

标签 统计

coordinates ×1

javascript ×1

jquery ×1

leaflet ×1

php ×1