こんにちは、地理位置情報を使用してGoogleの方向を取得しようとしています。地理位置情報の部分が完了しました。方向とリンクしており、正常に機能します。問題は、動的にしようとしたときに、さまざまなページのさまざまなオブジェクトの方向を取得することですut私はそれを動作させることができません.宛先スペクションで変数をエコーすることはできますが、それは機能しますが、ソースコードでは、宛先はコンテンツではなく変数です. 私のコードはこちら
<?php $rows = mysql_fetch_array($results) or die(mysql_error());
echo '<script>';
echo 'if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(function (position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var coords = new google.maps.LatLng(latitude, longitude);
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions ={
zoom: 15,
center: coords,
mapTypeControl: true,
navigationControlOptions:{
style: google.maps.NavigationControlStyle.SMALL
},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById(\'panel\'));
var request = {
origin: coords,';
$geo = $rows['GEO'];
echo 'destination: \'$geo\',
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
});
}
google.maps.event.addDomListener(window, \'load\', initialize);';
echo '</script>';
?>
誰かが私が間違っていることを知っている場合は、私に知らせてください。助けてくれてありがとう。
編集
私のクエリ(ページ上の他のすべてを表示するときに機能します)
$id = $_GET["id"] ;
$sql = "SELECT * FROM Posts where id = $id" ;
$results = mysql_query($sql) or die(mysql_error()) ;
データベースのGEOは地理的な場所ではなく、町や店などの名前です.