javascript - Update a Google Map Marker position by it's ID -
i creating google map markers , assigning them id follows:
var marker = new google.maps.marker({ position: new google.maps.latlng(data.latitude, data.longitude), map: map, id: data.id });
this results in markers appearing on map want update position of markers @ later time, how can grab marker id have assigned , update it's position?
i understand can update position setposition(latlng:latlng) on marker object in google api how grab marker it's id?
try code
<script src="https://maps.googleapis.com/maps/api/js?key=your-api-key&libraries=places" type="text/javascript"></script> <script> $(document).ready(function () { var long = $('#contentplaceholder1_hidlog').val(); var lati = $('#contentplaceholder1_hidlat').val(); var mapcenter = new google.maps.latlng(lati, long); var map; map_initialize(); function map_initialize() { var googlemapoptions = { center: mapcenter, zoom: 18, pancontrol: true, zoomcontrol: true, zoomcontroloptions: { style: google.maps.zoomcontrolstyle.small }, scalecontrol: true, maptypeid: google.maps.maptypeid.roadmap }; var marker = new google.maps.marker({ position: mapcenter, title: "event map" }); map = new google.maps.map(document.getelementbyid("google_map"), googlemapoptions); marker.setmap(map); } var getcen = map.getcenter(); google.maps.event.adddomlistener(window, 'resize', function () { map.setcenter(getcen); }); google.maps.event.adddomlistener(window, 'load', map_initialize()); google.maps.event.adddomlistener(window, "resize", resizingmap()); $('#showmap').on('show.bs.modal', function () { resizemap(); }) function resizemap() { if (typeof map == "undefined") return; settimeout(function () { resizingmap(); }, 400); } function resizingmap() { if (typeof map == "undefined") return; var center = map.getcenter(); google.maps.event.trigger(map, "resize"); map.setcenter(center); } }); </script>
Comments
Post a Comment