1
<?php echo $lat; ?>, 
<?php echo $lng; ?>) 

我正在尝试使用此页面中的代码使用谷歌在地图上方或下方的页面上获取坐标和 dprint, http: //www.galengrover.com/projects/PHPGoogleMaps-Examples/geolocation.php

我似乎不明白这是如何工作的。

require( '_system/autoload.php' );
$map_options = array(
'map_id'        => 'map23',
'draggable'     => true,
'center'        => 'San Diego, CA',
'height'        => '500px',
'width'         => '500px',
'zoom'          => 16,
'bicycle_layer' => true
);
$map = new \PHPGoogleMaps\Map( $map_options );

// 
$marker = \PHPGoogleMaps\Overlay\Marker::createFromUserLocation( array( 'geolocation_high_accuracy' => true, 'geolocation_timeout' => 10000 ) );

$map->addObject( $marker );

// If you want to set geolocation options you must call enableGeolocation() explicitly
// Otherwise it will be called for you when you use geolocation functions
$map->enableGeolocation( 5000, true );




// Set the loading content. This will display while the browser geolocates the user.
$map->setLoadingContent('<div style="background:#eee;height:300px;padding: 200px 0 0 0;text-align:center;"><img src="_images/loading.gif" style="display:block; margin: auto;"><p>Locating you...</p></div>'); ?>

<!DOCTYPE html>
<html lang="en">    
  <head>    
    <meta charset="utf-8">  
<title>Ground Overlays - 
  <?php echo PAGE_TITLE ?>
</title>    
<link rel="stylesheet" type="text/css" href="_css/style.css">       
<?php $map->printHeaderJS() ?>  
<?php $map->printMapJS() ?>
</head>
  <body><h1>Geolocation</h1>( 
    <?php require( '_system/nav.php' ) ?> 
<p>This example finds your location and centers the map on it. It also uses map::setLoadingContent() to display a loading message to the user.
</p>
<?php $map->printMap() ?>(
<?php echo $lat; ?>, 
<?php echo $lng; ?>) 

4

1 回答 1

0

编辑

我编辑了代码来向您展示这一点。请参阅 geosuccess() 函数。它会提醒你的坐标。一切都存储在“this”中,因此如果您在谷歌浏览器中进入控制台并输入“this”,您将在那里看到所有数据。

<?php

// This is for my examples
require( '_system/config.php' );

// Autoload stuff
require( '_system/autoload.php' );

$map = new \PHPGoogleMaps\Map;

// 
$marker = \PHPGoogleMaps\Overlay\Marker::createFromUserLocation( array( 'geolocation_high_accuracy' => true, 'geolocation_timeout' => 10000 ) );

$map->addObject( $marker );

// If you want to set geolocation options you must call enableGeolocation() explicitly
// Otherwise it will be called for you when you use geolocation functions
$map->enableGeolocation( 5000, true );
$map->centerOnUser( \PHPGoogleMaps\Service\Geocoder::geocode('New York, NY') );
$map->setWidth('500px');
$map->setHeight('500px');
$map->setZoom(16);

// Set the callbacks
$map->setGeolocationFailCallback( 'geofail' );
$map->setGeolocationSuccessCallback( 'geosuccess' );

// Set the loading content. This will display while the browser geolocates the user.
$map->setLoadingContent('<div style="background:#eee;height:300px;padding: 200px 0 0 0;text-align:center;"><img src="_images/loading.gif" style="display:block; margin: auto;"><p>Locating you...</p></div>');
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Geolocation - <?php echo PAGE_TITLE ?></title>
    <link rel="stylesheet" type="text/css" href="_css/style.css">
    <?php $map->printHeaderJS() ?>
    <?php $map->printMapJS() ?>
    <script type="text/javascript">
    function geofail() {
        alert( 'geolocation failed' );
    }
    function geosuccess() {
        alert("Lat:" + this.geolocation.hb + " Long: " + this.geolocation.ib);
        //alert( 'geolocation succeeded' );
    }
    </script>
</head>
<body>

<h1>Geolocation</h1>
<?php require( '_system/nav.php' ) ?>

<p>This example finds your location and centers the map on it. It also uses map::setLoadingContent() to display a loading message to the user.</p>

<?php $map->printMap() ?>

</body>

</html>
于 2013-04-13T20:04:45.740 回答