[英]Unable to pass javascript variables into Google Maps API
我在php文件中使用以下代碼
<script>
var geocoder = new google.maps.Geocoder();
geocoder.geocode( {'address': '<?php echo $element['singleCoords']; ?>' },
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
firstLoc = results[0].geometry.location;
var gmap<?php echo $element['id']; ?>_marker = new google.maps.Marker({
position: new google.maps.LatLng(firstLoc)
當我第firstLoc
警報firstLoc
,長形和緯度顯示為:5.34 ..,5,6 ...
但是,當我在函數google.maps.LatLng()
使用變量firstLoc
,我可以在Chrome的代碼瀏覽器中看到,僅傳遞了變量名稱,而沒有傳遞長整數和經緯度數字。
在代碼瀏覽器中,我看到了以下內容:
new google.maps.LatLng(firstLoc)
但我想看看:
new google.maps.LatLng(5.34.., 5,6...).
我究竟做錯了什么?
您是否需要將位置設置為LatLng坐標
根據Google Maps doco,您可以只將results[0].geometry.location
到位置
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.