마커를 지우고 새 마커를 추가하고 jQuery-ui-map의 중심 위치를 동적으로 설정하려면 다음 방법을 사용할 수 있습니다.
//clear all markers
$('#map_canvas').gmap('clear', 'markers');
// add a new marker
var $marker = $('#map_canvas').gmap('addMarker', {id: i, 'position': new google.maps.LatLng(cityList[i][1], cityList[i][2]), title: cityList[i][0]});
// on marker click show the description
$marker.click(function() {
$('#map_canvas').gmap('openInfoWindow', {'content': cityList[this.id][0]}, this);
});
// update the map's center position
$("#map_canvas").gmap("get", "map").panTo(new google.maps.LatLng(cityList[i][1], cityList[i][2]));
은 Google Maps documentation 따르면 panTo
방법은 소정의 위도 경도를 포함하는 데 필요한 최소량으로지도를 패닝. 가능한 한 많은 경계가 표시된다는 점을 제외하고는 맵에서 경계가 어디인지 보장하지 않습니다. 경계가지도에있는 경우지도 유형과 탐색 (이동, 확대/축소 및 스트리트 뷰) 컨트롤로 경계가 지정된 영역 내부에 경계가 배치됩니다. 범위가지도보다 큰 경우 경계의 북서쪽 구석을 포함하도록지도가 이동됩니다. 지도의 위치 변화가지도의 너비와 높이보다 작 으면 전환이 부드럽게 움직입니다.
아래에서 샘플을 찾을 수 있습니다. 당신이 시카고 버튼을 누르면 마커가 추가되고지도의 중심 위치는 시카고
<!doctype html>
<html lang="en">
<head>
<title>jQuery mobile with Google maps - Google maps jQuery plugin</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3&sensor=false&language=en"> </script>
<script type="text/javascript" src="http://jquery-ui-map.googlecode.com/svn/trunk/ui/min/jquery.ui.map.min.js"></script>
<script type="text/javascript">
var mobileDemo = { 'center': '41,-87', 'zoom': 7 },
cityList = [
['Chicago', 41.850033,-87.6500523, 1],
['Kentucki', 37.735377,-86.572266, 2]
];
function initialize()
{
$('#map_canvas').gmap({ 'center': mobileDemo.center, 'zoom': mobileDemo.zoom, 'disableDefaultUI':false });
}
function addMarker(i)
{
//clear all markers
$('#map_canvas').gmap('clear', 'markers');
// add a new marker
var $marker = $('#map_canvas').gmap('addMarker', {id: i, 'position': new google.maps.LatLng(cityList[i][1], cityList[i][2]), title: cityList[i][0]});
// on marker click show the description
$marker.click(function() {
$('#map_canvas').gmap('openInfoWindow', {'content': cityList[this.id][0]}, this);
});
// set the map's center position
$("#map_canvas").gmap("get", "map").panTo(new google.maps.LatLng(cityList[i][1], cityList[i][2]));
}
$(document).on("pageinit", "#basic-map", function() {
initialize();
});
$(document).on('click', '.add-marker', function(e) {
e.preventDefault();
addMarker(this.id);
});
</script>
</head>
<body>
<div id="basic-map" data-role="page">
<div data-role="header">
<h1><a data-ajax="false" href="/">jQuery mobile with Google maps v3</a> examples</h1>
<a data-rel="back">Back</a>
</div>
<div data-role="content">
<div class="ui-bar-c ui-corner-all ui-shadow" style="padding:1em;">
<div id="map_canvas" style="height:350px;"></div>
</div>
<a href="#" id="0" class="add-marker" data-role="button" data-theme="b">Chicago</a>
<a href="#" id="1" class="add-marker" data-role="button" data-theme="b">Kentucki</a>
</div>
</div>
</body>
</html>
난이 도움이되기를 바랍니다에 업데이트됩니다.
같은 문제가 있습니다. '마커를 클릭하면 툴팁의 주소가 새로 고쳐 지지만 위치는 동일하게 보입니다.' 답변을 제공해주세요 ... –