我想用PHP來添加自定義標記使用GET。我可以進入if語句,並加載地圖,但這不會添加標記,我對JavaScript不熟悉。我只是使用文檔來完成我需要做的事情。我試圖使用PHP來添加標記到Javascript(谷歌地圖),但它不工作我已經注意到它的方式
裏面autolocategmap.js
它只包含Javascript來初始化地圖和使用地理定位來找到用戶,它的工作原理很好,唯一的問題是標記不出現在加載或刷新或任何東西,我甚至不知道如果我可以通過包括<script>custom marker</script>
來追加這個額外的腳本,任何信息將非常感謝。
<?php
/* Include header and config and set variable*/
require_once('config.inc.php');
require_once($rootdir . $dirsubfolder . 'navbar.php');
$route = $_GET['route'];
?>
<?php
/* User wants to retrieve their route */
if ((isset($route)) && (strcmp($route, "sunauto") == 0)) {
?>
<script src="js/autolocategmap.js"></script>
<script>
addMarker('56.742111','-111.481753','Stop 3', 'Arrives at: 6:00am');
</script>
<?php
}
?>
autolocategmap.js:
/**
* Basic Map
*/
$(document).ready(function(){
var map = new GMaps({
div: '#gmap',
lat: 56.744901,
lng: -111.473049,
zoom: 16,
zoomControl : true,
zoomControlOpt: {
style : 'SMALL',
position: 'TOP_LEFT'
},
panControl : false,
});
GMaps.geolocate({
success: function(position) {
map.setCenter(position.coords.latitude, position.coords.longitude);
},
error: function(error) {
alert('Geolocation failed: '+error.message);
},
not_supported: function() {
alert("Your browser does not support geolocation");
}
});
$(window).resize(function() {
var h = $(window).height(),
offsetTop = 150; // Calculate the top offset
$('#gmap').css('height', (h - offsetTop));
}).resize();
});
function addMarker(lat,lng,title,window){
map.addMarker({
lat: lat,
lng: lng,
title: title,
infoWindow: window
});
}
只是這件事本身並沒有給很多工作。你能否顯示autolocategmap.js中創建實際地圖的代碼。 – Rafe 2013-03-03 17:33:54
@Rafe你去 – Datsik 2013-03-03 17:42:45
把添加標記放入js中的一個函數中。然後用coords和文本調用該函數。 不確定,但問題可能是外部腳本不知道'map'實際上是什麼。 – Rafe 2013-03-03 17:54:01