I have several different cards. When I click on the link, I show the map with the given coordinates and put a marker on this place! But when I start to increase the zoom, the marker shifts!

 // initialize the card
 var mapModule = (function () {
     'use strict';

     var mapSection = $ ('# map') [0];

     return {
         // Add a marker
         addMarker: function (latitude, longitude, map) {
             new google.maps.Marker ({
                 position: {
                     lat: latitude,
                     lng: longitude
                 },
                 icon: new google.maps.MarkerImage ('/ images / mapMarker.png',
                     new google.maps.Size (84.95),
                     new google.maps.Point (0,0),
                     new google.maps.Point (0.95)
                 ),
                 map: map
             });
         },

         // Initialize the card
         initMap: function (latitude, longitude) {
             var mapPosition = new google.maps.LatLng (latitude, longitude),
                 mapOptions = {
                     zoom: 14,
                     center: mapPosition,
                     scaleControl: false,
                     zoomControl: false,
                     streetViewControl: false,
                     mapTypeControl: false
                 },

                 map = new google.maps.Map (mapSection, mapOptions);

             mapModule.addMarker (latitude, longitude, map);
         }
     }
 } ());

 // Open a map with given coordinates
 $ ('. showMap'). on ('click', function (event) {
     event.preventDefault ();

     $ ('. showMap'). removeClass ('act');
     $ (this) .addClass ('act');

     var latitude = $ (this) .data ('latitude'),
         longitude = $ (this) .data ('longitude');

     mapModule.initMap (latitude, longitude);
 });

What is the problem?

Update

There is no site, I do it locally!

JsFiddle example

//инициализация ΠΊΠ°Ρ€Ρ‚Ρ‹ var mapModule = (function() { 'use strict'; var mapSection = $('#map')[0]; return { // Π”ΠΎΠ±Π°Π²ΠΈΠΌ ΠΌΠ°Ρ€ΠΊΠ΅Ρ€ addMarker: function(latitude, longitude, map) { var marker = new google.maps.Marker({ position: { lat: latitude, lng: longitude }, icon: new google.maps.MarkerImage('data:image/png;base64,/x8FCx8JFyMNIycRLysVOy8ZRzMdUzchXzslazspdz8tg0Mxj0c1m0s5p089s1NBv1dFy1tJ11tN419R72NV+2daB2taE29eH3NiK3dmN3dqQ3tuT39yW4N2Z4d6c4t+f4+Ci5OGl5eKo5eOr5uSu5+Wx6Oa06ee36ui66+m97OrA7OvD7ezG7u3J7+7M8O/P8fDS8v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8LKUP46Ah1SAAAAAElFTkSuQmCC', new google.maps.Size(84, 95), new google.maps.Point(0, 0), new google.maps.Point(84, 95) ), map: map }); }, // Π˜Π½ΠΈΡ†ΠΈΠ°Π»ΠΈΠ·Π°Ρ†ΠΈΡ ΠΊΠ°Ρ€Ρ‚Ρ‹ initMap: function(latitude, longitude) { var mapPosition = new google.maps.LatLng(latitude, longitude), mapOptions = { zoom: 14, center: mapPosition, scaleControl: false, zoomControl: false, streetViewControl: false, mapTypeControl: false }, map = new google.maps.Map(mapSection, mapOptions); mapModule.addMarker(latitude, longitude, map); } } }()); mapModule.initMap(54.6199796, 39.790707); 
 #map { height: 400px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script> <script src="https://maps.googleapis.com/maps/api/js"></script> <div id="map"></div> 

  • Give a link to your site where you can see the problem in reality - Alex

1 answer 1

You, as I understand it, the new google.maps.Point(84, 95) parameter of the marker is incorrect.

Necessary: new google.maps.Point(42,95) Ie anchor point in the middle-bottom of the image

pictures in base64 are furious))

  • I checked the card at the link you specified in the comment to my answer. The map does scale with offset to the mouse cursor. Try to move the cursor to the edge of the map and zoom in on it. Take a closer look. However, the vehicle was right that the icon was moving. At work eyes zamylilas, not initially noticed. - VenZell
  • @VenZell we did not understand each other)) I meant that the marker does not move to the sides (on that link) and should not dance. I thought you talked about it. - Alexey Shimansky