How to move the center position of google map

前端 未结 2 352
执笔经年
执笔经年 2021-01-12 09:44

I am creating a google map in a script with the following code -

var mapElement,
    parent,
    mapOptions,
    map,
    marker,
    latLong,
    openMarke         


        
相关标签:
2条回答
  • 2021-01-12 10:16

    forget all that crap this is what works if you want to reuse a google map marker or move a google map marker, or recenter a google map marker.

    var lo = <yourval>;
    var la = <yourval>;
    var midpoint = {lat:la, lng:lo };
    marker.setPosition(midpoint);
    

    if you want to destroy a google maps marker or delete a google maps marker

    marker.setMap(null);
    
    0 讨论(0)
  • 2021-01-12 10:28

    You can use .setCenter() to move the center of the map

    map.setCenter(marker.getPosition());
    

    Update

    Convert the LatLng with .fromLatLngToDivPixel() into a Point add an offset and convert it back into a LatLng with .fromDivPixelToLatLng()

    0 讨论(0)
提交回复
热议问题