中心最后一个标记Google Maps

时间:2012-03-02 17:28:22

标签: javascript google-maps

我有谷歌地图,我必须将屏幕放在最后创建的标记上,这些标记是自动创建的,来自我的数据库的数据,我会有很多标记,但我想要正面屏幕中间的最后一个标记。

// this method create markers for a determinated position at some map
function createMarker(position, map){
                var marker = new google.maps.Marker(
                {
                    position: position,
                    map: map,
                    title: "Pizza Way"
                });
            }
//this map get from database the points and initialize the markers on map
function initMarkers(map){
                var m = locsjs.split(",");
                var latit;
                var longit;

                var indexesLat = 4;
                var indexesLon = 5;

                var latitudeFinal;
                var longitudeFinal;

                var point;

                for(i = 0;i <= (m.length/7)-1; i++){
                    latit = m[indexesLat].split(":")[1];
                    longit = m[indexesLon].split(":")[1];

                    indexesLat += 7;
                    indexesLon += 7;

                    latitudeFinal = parseFloat(Number(latit.substring(6,latit.length-6)));
                    longitudeFinal = parseFloat(Number(longit.substring(6,longit.length-6)));
                    point = new google.maps.LatLng(latitudeFinal, longitudeFinal);

                    createMarker(point, map);
                }
            }

1 个答案:

答案 0 :(得分:1)

呼叫

map.setCenter(point);

initMarkers()

的末尾