Martyn Ball Martyn Ball - 1 year ago 57
jQuery Question

jQuery Plugin, can't target ID

as you can see i'm applying a function to an ID like so:

$("map_canvas").multimap({ });

And this is the function, however
is displaying
[object Object]
and I think it's getting the window, not my DIV with that ID...

(function($) {

$.fn.multimap = function( options ) {

var container = $( this );

What am I doing wrong?


Still getting an error when I try to use
like so:

(function($) {

$.fn.multimap = function( options ) {

// This is the easiest way to have default options.
var settings = $.extend({
// These are the defaults.
locations: [
['Address Title', 'Add Address Here', {lat: 53.008756, lng: -2.181422}]
iconSize: { width: 70, height: 70 },
zoom: 10,
mapType: 'ROADMAP'

}, options );

var map;
var bounds = new google.maps.LatLngBounds();

// Override handles
var i_iconSize = settings.iconSize;
if (settings.iconSize.constructor !== Object) {
i_iconSize = { width: settings.iconSize, height: settings.iconSize };

function initialize() {
var lat = parseFloat(settings.locations[0][2]['lat']);
var lng = parseFloat(settings.locations[0][2]['lng']);
var i_mapType;

switch(settings.mapType) {
case "ROADMAP":
i_mapType = google.maps.MapTypeId.ROADMAP;
i_mapType = google.maps.MapTypeId.SATELLITE;
case "HYBRID":
i_mapType = google.maps.MapTypeId.HYBRID;
case "TERRAIN":
i_mapType = google.maps.MapTypeId.TERRAIN;

map = new google.maps.Map(
this, {
// Initial center point, changes ones the markers are added though
center: new google.maps.LatLng(lat,lng),

// This doesn't seme to work, seems to just scale to fit all markers in at the moment
zoom: settings.zoom,

// Change the map type, not sure what the others are called
mapTypeId: google.maps.MapTypeId.ROADMAP

for (i = 0; i < (settings.locations).length; i++) {
createMarker(settings.locations, i);


Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.

Answer Source

Used # before id name In JQuery ex: $("#idname") select element with id="idname"

If you used the class then used . before the class name ex: $(".classname") Select all elements with class="classname"

$("map_canvas").multimap({ });


$("#map_canvas").multimap({ });