Need Google Maps to open Multiple Marker Popups with Fancybox

planetbob

I am creating a Google map with multiple markers that I want to popup into a Fancybox lightbox when clicked on. I must admit, I am quite a novice at javascript and Google Maps API.

I have put some pieces of different sample scripts together and come up with something that actually works decently. I have the markers the way I want them (well, without captions... which I still have to figure out), the style of map the way I want it, and I even have the markers popping up lightboxes when clicked on.

However, all markers end up opening one URL in the lightbox. I guess that makes a bit of sense. The Fancybox code is being distributed to all the markers, instead of each one individually. I tried to make another argument with a url and pass it into the Fancybox script, but it still just picks up the last marker's url and uses it for all the markers. How would I be able to get the URL to work for each marker instead of all the markers at once?

I did find a similar question on here:

Multiple fancybox google map

However, it seams to use a different route of attacking the same issue. Plus, I can't seem to get their script to work by itself, let alone integrate it with my code. So, while I get how the solution works for them, it doesn't seem to help me.

My code is as follows:

var map;

var MY_MAPTYPE_ID = 'custom_style';

function initialize() {

  var featureOpts = [
    {
      stylers: [
        { hue: '#CCCCCC' },
        { saturation: '-100' },     
        { visibility: 'simplified' },
        { gamma: 2 },
        { weight: .4 }
      ]
    },
    {
      elementType: 'labels',
      stylers: [
        { visibility: 'off' }
      ]
    },
    {
      featureType: 'water',
      stylers: [
        { color: '#efefef' }
      ]
    }
  ];

  var mapOptions = {
    zoom: 9,
    scrollwheel: false,
    keyboardShortcuts: false,
    disableDefaultUI: true,
    center: new google.maps.LatLng(34.0531553, -84.3615928),
    mapTypeControlOptions: {
      mapTypeIds: [google.maps.MapTypeId.ROADMAP, MY_MAPTYPE_ID]
    },
    mapTypeId: MY_MAPTYPE_ID
  };

  map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

  var styledMapOptions = {
    name: 'Custom Style'
  };

  var customMapType = new google.maps.StyledMapType(featureOpts, styledMapOptions);

  map.mapTypes.set(MY_MAPTYPE_ID, customMapType);

 setMarkers(map, schools);
}


var schools = [
  ['Canton', 34.2352063, -84.4846274, 4, 'popup.htm'],
  ['Austell', 33.8158106, -84.6334938999999, 3, 'popup.htm'],
  ['Marietta', 33.9578674, -84.5532791, 2, 'popup.htm'],
  ['Atlanta', 33.7635085, -84.43030209999999, 1, 'popup2.htm']
];

function setMarkers(map, locations) {

  var image = {
    url: 'images/fml-home.png',

    size: new google.maps.Size(67, 63),

    origin: new google.maps.Point(0,0),

    anchor: new google.maps.Point(0, 63)
  };
  var shadow = {
    url: 'images/fml-shadow.png',

    size: new google.maps.Size(45, 18),
    origin: new google.maps.Point(0,0),
    anchor: new google.maps.Point(0, 18)
  };

  var shape = {
      coord: [1, 1, 1, 67, 60, 67, 60 , 1],
      type: 'poly'
  };
  for (var i = 0; i < locations.length; i++) {
    var schools = locations[i];

    var myLatLng = new google.maps.LatLng(schools[1], schools[2]);

    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        shadow: shadow,
        icon: image,
        shape: shape,
        title: schools[0],
        zIndex: schools[3]

    });

        var href = schools[4];

    google.maps.event.addListener(marker, 'click', function() {

         $.fancybox({
    frameWidth    : 800,
    frameHeight   : 600,
    href : href,
    type : 'iframe'
        });
            });

}

}

google.maps.event.addDomListener(window, 'load', initialize);
Lukas Greblikas

Try this:

marker["href"] = schools[4];

google.maps.event.addListener(marker, 'click', function() {

     $.fancybox({
       frameWidth    : 800,
       frameHeight   : 600,
       href : this.href,
       type : 'iframe'
     });
});

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Google Maps jQuery Marker not Displaying

分類Dev

Render multiple marker in react-native-maps

分類Dev

Google Maps API - Marker array only showing the first marker

分類Dev

Flutter Image overlay for Google Maps Marker

分類Dev

Removing marker by latitude/longitude in google maps

分類Dev

Adding marker clusterer to google maps with for-loop?

分類Dev

Parse JSON response for Google Maps Marker in Android

分類Dev

Fluter - Google Maps, is it possible to use a Material Icon as a map marker?

分類Dev

Google static maps - group some points with custom marker

分類Dev

Recognise click over current location marker in Android Google Maps

分類Dev

Google Maps multiple maps displayed instead of one

分類Dev

`vue2-google-maps`で` new google.maps.Marker() `を使用する方法

分類Dev

Plotting multiple polylines on Google Maps

分類Dev

Fit Bounds for Multiple Polygons google Maps

分類Dev

Google Maps Api - multiple items in infowindow

分類Dev

Removing multiple circles google maps api

分類Dev

How to hide all opened marker popups in mapbox-gl?

分類Dev

How to add marker onClick and show my geolocation in google-maps-react?

分類Dev

Google maps react only displaying marker of last rendered object from state array

分類Dev

Issues with Google Maps Javascript API, Marker and Polylines NOT SHOWING together on a React.js App

分類Dev

How would I integrate a Google Maps marker input from Javascript into PHP?

分類Dev

Google Maps JavaScript API v3 changing marker and add satellite view

分類Dev

Why is only one Google Maps V2 marker displaying in a Fragment?

分類Dev

How to implement centered marker in Google Maps API v3 with Ionic & Angular

分類Dev

Google Maps Marker Clusterer:ネストされたクリック処理

分類Dev

Google maps javascript - Marker array, how do I get the lat/lon?

分類Dev

Uncaught ReferenceError:googleはgoogle.maps.Marker()で定義されていません

分類Dev

Google Maps Marker ClustererPlusで混合コンテンツの警告を回避する方法

分類Dev

How to Add Google Maps with Multiple Markers Showing Infowindows on Load and on Click

Related 関連記事

  1. 1

    Google Maps jQuery Marker not Displaying

  2. 2

    Render multiple marker in react-native-maps

  3. 3

    Google Maps API - Marker array only showing the first marker

  4. 4

    Flutter Image overlay for Google Maps Marker

  5. 5

    Removing marker by latitude/longitude in google maps

  6. 6

    Adding marker clusterer to google maps with for-loop?

  7. 7

    Parse JSON response for Google Maps Marker in Android

  8. 8

    Fluter - Google Maps, is it possible to use a Material Icon as a map marker?

  9. 9

    Google static maps - group some points with custom marker

  10. 10

    Recognise click over current location marker in Android Google Maps

  11. 11

    Google Maps multiple maps displayed instead of one

  12. 12

    `vue2-google-maps`で` new google.maps.Marker() `を使用する方法

  13. 13

    Plotting multiple polylines on Google Maps

  14. 14

    Fit Bounds for Multiple Polygons google Maps

  15. 15

    Google Maps Api - multiple items in infowindow

  16. 16

    Removing multiple circles google maps api

  17. 17

    How to hide all opened marker popups in mapbox-gl?

  18. 18

    How to add marker onClick and show my geolocation in google-maps-react?

  19. 19

    Google maps react only displaying marker of last rendered object from state array

  20. 20

    Issues with Google Maps Javascript API, Marker and Polylines NOT SHOWING together on a React.js App

  21. 21

    How would I integrate a Google Maps marker input from Javascript into PHP?

  22. 22

    Google Maps JavaScript API v3 changing marker and add satellite view

  23. 23

    Why is only one Google Maps V2 marker displaying in a Fragment?

  24. 24

    How to implement centered marker in Google Maps API v3 with Ionic & Angular

  25. 25

    Google Maps Marker Clusterer:ネストされたクリック処理

  26. 26

    Google maps javascript - Marker array, how do I get the lat/lon?

  27. 27

    Uncaught ReferenceError:googleはgoogle.maps.Marker()で定義されていません

  28. 28

    Google Maps Marker ClustererPlusで混合コンテンツの警告を回避する方法

  29. 29

    How to Add Google Maps with Multiple Markers Showing Infowindows on Load and on Click

ホットタグ

アーカイブ