Setting a marker on google map

I am trying to set a marker on my google map. I think I do it the way Google wants, but the marker does not appear on the map. What am I doing wrong? You can see the implemented map here: http://nidarosnaprapati.no/wordpress/?page_id=66

<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(63.4242234, 10.4439311);
var myOptions = {
  zoom: 13,
  center: latlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
map.addOverlay(new GMarker(63.4242234, 10.4439311));
}
</script>
+3
source share
2 answers

The problem is that you are mixing google maps v2 code with google v3 maps. The addOverlay and GMarker functions are from google v2 maps. Replace them with google maps v3 code:

var marker = new google.maps.Marker({
    position: latlng, 
    map: map,
    title:"Hello World!"
});
+8
source

Each version is implemented differently. One uses G ~ in the global namespace, and the other is under the google.maps namespace. ~.

, JSON, - . . LatLng Marker.

, , Google.

var marker = new google.maps.Marker({
    position: latlng,
    map: map,
    icon: new google.maps.MarkerImage(
        "maps/images/point.png", // reference from your base
        new google.maps.Size(36, 36), // size of image to capture
        new google.maps.Point(0, 0), // start reference point on image (upper left)
        new google.maps.Point(10, 10), // point on image to center on latlng (scaled)
        new google.maps.Size(20, 20) // actual size on map
    )
});

, :

marker.setMap(null);
delete marker;
+2

Source: https://habr.com/ru/post/1754245/


All Articles