vendredi 17 juin 2016

jQuery Plugin Help, setting up settings

Attempting to convert some code i use into a plugin so it can be used elsewhere easier.

(function($) {

        $.fn.multimap = function( options ) {

            // This is the easiest way to have default options.
            var settings = $.extend({
                // These are the defaults.
                locations: ['Manchester Showroom', '69 Park Road, Manchester, Cheshire, SK16 5LX', {lat: 53.481079, lng: -2.0797}],
                backgroundColor: "white"
            }, options );


            // Use Google maps to get the lat and Lng values
            var locations = settings.locations;

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

            function initialize() {
                map = new google.maps.Map(
                document.getElementById("map_canvas"), {
                    // Initial center point, changes ones the markers are added though
                    center: new google.maps.LatLng(settings.locations[2]),

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

So i'm executing the plugin and it is working fine, except getting an error at google.maps.LatLng, however the object should work find as you can see this above in the settings.

The error:

js:32 InvalidValueError: setPosition: not a LatLng or LatLngLiteral: not an Object

Aucun commentaire:

Enregistrer un commentaire