谷歌地图v3 jquery移动获取中心纬度和经度



我试图在初始化地图后在地图上绘制标记。但是,我需要知道中心点液化天然气背阔肌。

我已经尝试使用这两个,但是我在chrome js中收到"未捕获的范围错误:超出最大调用堆栈大小";

$('#map_canvas').gmap('get', 'map').getCenter()); and also 
$('#map_canvas').gmap('option', 'center');
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="jquery-ui-map-3.0-rc/ui/jquery.ui.map.js"></script>
<script type="text/javascript" src="jquery-ui-map-3.0-rc/ui/jquery.ui.map.extensions.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script>
$('#map_page').live("pageshow", function() {
    function add_markers() {
        var location = $('#map_canvas').gmap('option', 'center');
    $.getJSON( 'http://localhost/motherly/android/index.php/api/venues?lat=' + location.lat() + '&lng=' + location.lng(), function(data) { 
        console.log(data['response']);
        $.each(data.response, function(i, marker) {
            // console.log(marker.lat, marker.lng);
            $('#map_canvas').gmap('addMarker', { 
                'position': new google.maps.LatLng(marker.lat, marker.lng), 
                'bounds': true 
            }).click(function() {
                $('#map_canvas').gmap('openInfoWindow', { 'content': marker.name }, this);
            });
        });
    }); 
    }
    function initialize(lat,lng) {
        $('#map_canvas').gmap({'center' : new google.maps.LatLng(lat, lng), 'callback': function(){
            add_markers();
        }});
    }
    if(navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position){
            console.log(position);
            initialize(position.coords.latitude,position.coords.longitude);
            // google.maps.event
        });
    }
});
抱歉,

伙计们,我意识到问题是我在地图的构造函数调用了 draw 方法,这很有意义,地图对象没有初始化。

因此,回顾一下这个问题是 add_markers() 方法位于此构造函数内部(将 add_markers() 移到此行下方);

$('#map_canvas').gmap({'center' : new google.maps.LatLng(lat, lng), 'callback': function(){
}});

最新更新