Google map V3 Set Center to specific Marker

后端 未结 6 849
深忆病人
深忆病人 2020-12-05 13:04

I am using Google Map V3 to display a list of markers pulled from a DB, using MYsql and PHP. MY markers are set on the map using the full address (from DB, including postcod

6条回答
  •  盖世英雄少女心
    2020-12-05 13:26

    If you want to center map onto a marker and you have the cordinate, something like click on a list item and the map should center on that coordinate then the following code will work:

    In HTML:

    In Controller:

    $scope.focusMarker = function (coords) {
        map.setCenter(new google.maps.LatLng(coords.Latitude, coords.Longitude));
        map.setZoom(14);
    }
    

    Location Object:

    {
        "Name": "Taj Mahal",
        "AddressLine": "Tajganj",
        "City": "Agra",
        "State": "Uttar Pradesh",
        "PhoneNumber": "1234 12344",
        "Latitude": "27.173891",
        "Longitude": "78.042068"
    }
    

提交回复
热议问题