私は時間のためにこれに取り組んできましたが、私はこの特定のシナリオのためにsetCenterへの正しいオブジェクトフィードを見つけることができないよう:setCenterは、私はそれに供給任意のオブジェクトを受け入れていないようです
var map,
currentPositionMarker,
mapCenter = new google.maps.LatLng(14.668626, 121.24295)
function initializeMap(){
map = new google.maps.Map(_('map'), {
zoom: 18,
center: mapCenter,
mapTypeId: 'roadmap',
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}
});
}
function locError(error) { alert("current position not be found");}
function setCurrentPosition(pos) {
currentPositionMarker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(
pos.coords.latitude,
pos.coords.longitude
),
title: "Current Position"
});
map.panTo(new google.maps.LatLng(
pos.coords.latitude,
pos.coords.longitude
));
}
function displayAndWatch(position) {
setCurrentPosition(position);
watchCurrentPosition(position);
}
function watchCurrentPosition(pos) {
var positionTimer = navigator.geolocation.watchPosition(
function (position) {
setMarkerPosition(
currentPositionMarker,
position
);
**map.setCenter(google.maps.LatLng(pos.coords.latitude,pos.coords.latitude));**
});
}
function setMarkerPosition(marker, position) {
marker.setPosition(
new google.maps.LatLng(
position.coords.latitude,
position.coords.longitude)
);
}
function initLocationProcedure() {
initializeMap();
infoWindow = new google.maps.InfoWindow({ maxWidth: 400 });
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(displayAndWatch, locError);
} else { alert("Geolocation API not supported"); }
}
(それぞれの変更が有効かどうかを確認するためにブロックを運転する必要があるので、特にイライラします)。 上記のmap.setCenterの行で、私が間違っていることを誰でも知っていますか?あなたはこのようにそれを設定する必要が
あなたは 'setCenter'呼び出しを行っているときは、' google.maps.LatLng'の前に 'new'を持っていないので、あなたが上がりませんLatLngオブジェクトを取得していない場合、LatLngへの非コンストラクタ呼び出しで何も返されないため、あなたは '未定義 'になっています。 –