【发布时间】:2015-02-12 23:09:52
【问题描述】:
当我试图用 PHP 回调一个 JavaScript 函数时,我需要一些帮助。我创建了 2 个完美地协同工作的类。在第一个利用 Google API 的案例中,我提取了用户在我的表单上选择的城市的纬度和经度,然后我将这些值传递给第二个类,该类利用另一个 API 显示该城市的天气预报服务。
我也想添加一个谷歌地图,以这种方式创建一个更完整的服务,显示所选城市的动态地图。
我注意到 Firebug 浏览器无法正确解析对象 $map 的两个提到的属性,您可以自己轻松地看到。 我真的不知道怎么回调标签里面的js函数,我需要。
我在这里与 PHP 一起使用的简单回显在这里不起作用。
希望有人可以帮助我。 这里是my page
这是我的一段代码不起作用:
/**
* Check for the real existence of the city, using the
* property $status of the instanced GeoLocalization class, here the object $map.
* This class exploits a Google API.
*/
if ( isset($missing) && empty($missing) && strlen($citta) > 1 && $map->status == 'OK' )
{
/**
* Use some properties of the object $map to show my user
* the chosen city and state in Italian.
* Show even the latitude and the longitudine.
* These values are those passed to the GeoWeather class.
*/
// show the location
echo '<ul id="display_location">' .
'<li class="rosso centra sottolineato grassetto">' . $map->formatted_address . '</li>' .
'<li>' . 'Latitudine: ' . $map->latitude . '</li>' .
'<li>' . 'Longitudine: ' . $map->longitude . '</li>' .
</ul>';
echo '<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script>';
echo '<script type="text/javascript">
var map;
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(<?php echo $map->latitude . ", " . $map->longitude; ?>)
};
map = new google.maps.Map(document.getElementById("googleStaticMap"), mapOptions);
}
</script>';
echo '<script type="text/javascript">initialize();</script>';
echo '<div id="googleStaticMap"></div>';
}
</body>
【问题讨论】:
标签: javascript php google-maps google-maps-api-3