我有一个我正在构建的应用程序的 div 移动页面。当我定义:
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
无论是在我的功能内,还是在它之外,然后尝试在以下位置使用它们:
latlng1 = new google.maps.LatLng(latitude, longitude);
我的页面没有加载,只给了我 CSS 边框等
但是,如果我只是简单地删除(latitude, longitude);
并放入(40.716948, -74.003563);
它就latlng1 = new google.maps.LatLng(40.716948, -74.003563);
可以了。
为什么定义的变量值没有传递到 LatLng ?
这是源代码的 div 部分:
<!-- My Location -->
<div data-role="page" data-theme="b" id="my_loc" class="page-map1">
<div data-role="header" data-theme="a">
<a href="#home" data-icon="arrow-l">Back</a>
<h1>My Location</h1>
</div>
<div data-role="content">
<h2>Map</h2>
<div id="map1" class="gmap"></div>
<script type="text/javascript">
var map1, latlng1, options1, latitude, longitude;
//these lat and long variable definitions are messing me up !!
//latitude = position.coords.latitude;
//longitude = position.coords.longitude;
function initialize() {
latlng1 = new google.maps.LatLng(latitude, longitude);
//40.716948, -74.003563);
//Lat, Lon);
//(position.coords.latitude, position.coords.longitude);
//40.716948, -74.003563); change from new jersey
options1 = { zoom: 14, center: latlng1, mapTypeId:google.maps.MapTypeId.ROADMAP };
map1 = new google.maps.Map(document.getElementById("map1"), options1);
}
$('.page-map1').live("pagecreate", function() {
initialize();
});
$('.page-map1').live('pageshow',function(){
console.log("test");
google.maps.event.trigger(map1, 'resize');
map1.setOptions(options1);
});
</script>
</div>
</div>
<div data-role="page" id="map" data-theme="a">
<div data-role="header" data-position="fixed">
<h1>Page Header</h1>
</div>
<div data-role="content">
<p class="errorMsg">Your location could not be determined.</p>
<div id="gMap"></div>
</div>
<div data-role="footer" data-position="fixed">
<h4>TRACK</h4>
</div>
</div>
<!-- /My Location -->
</div>