Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to addShape() on a google map with jquery-ui-map correctly

I am using the following code to add a shape to the map by using jquery, jqueryui-map and google maps API

$('#map_canvas').gmap('getCurrentPosition', function(position, status) {
            if ( status === 'OK' ) {
                var clientPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                $('#map_canvas').gmap('addMarker', {'position': clientPosition, 'bounds': false});
                $("#map_canvas").gmap("option", "center", clientPosition);
                $('#map_canvas').gmap('option', 'zoom', 14);
                $('#map_canvas').gmap('addShape', 'Circle', {
                    'strokeColor': "#008595",
                    'strokeOpacity': 0.8,
                    'strokeWeight': 2,
                    'fillColor': "#008595",
                    'fillOpacity': 0.35,
                    'center': clientPosition,
                    'radius': 50,
                    'clickable': false });
            }
});

I also tried to call the .addShape method on $('#map_canvas'). but I only get the following Error:

Uncaught TypeError: Cannot call method 'apply' of undefined jquery.ui.map.js:46
$.a.$.fn.(anonymous function) jquery.ui.map.js:46
e.extend.each jquery.min.js:2
e.fn.e.each jquery.min.js:2
$.a.$.fn.(anonymous function) jquery.ui.map.js:40
(anonymous function) :8080:397
$.extend.getCurrentPosition

Does anyone know how to solve this issue? The example on http://jquery-ui-map.googlecode.com/svn/trunk/demos/jquery-google-maps-geolocation.html works for some reason.. I am just not able to figure out the actual difference.. Maybe I am to blind right now ;)

Thanks,

Pat

like image 867
wzr1337 Avatar asked Jul 05 '12 07:07

wzr1337


2 Answers

Had the same issue, spawning from the same documentation which failed to mention to include jquery.ui.map.overlays.js

The code says

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="PATH_TO_PLUGIN/jquery.ui.map.js"></script>
<script type="text/javascript" src="PATH_TO_PLUGIN/jquery.ui.map.extensions.js"></script>

when in fact you need

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript" src="PATH_TO_PLUGIN/jquery.ui.map.js"></script>
<script type="text/javascript" src="PATH_TO_PLUGIN/jquery.ui.map.overlays.js"></script>

In fact, tested and it works without jquery.ui.map.extensions.js

like image 198
Moak Avatar answered Nov 15 '22 09:11

Moak


I commented jquery.ui.map.extensions.js and added jquery.ui.map.overlays.js but it did not help

<script type="text/javascript" charset="utf-8" src="js/jquery-1.9.1.min.js"> </script> 
<script type="text/javascript" src="js/jquery.ui.map.js"></script> 
<!--script type="text/javascript" src="js/jquery.ui.map.extensions.js"></script--> 
<script type="text/javascript" src="js/jquery.ui.map.overlays.js"></script>

this lead to Object # has no method 'getCurrentPosition' error.

I then uncommented jquery.ui.map.extensions.js and then it worked for me.

<script type="text/javascript" charset="utf-8" src="js/jquery-1.9.1.min.js"> </script> 
<script type="text/javascript" src="js/jquery.ui.map.js"></script> 
<script type="text/javascript" src="js/jquery.ui.map.extensions.js"></script> 
<script type="text/javascript" src="js/jquery.ui.map.overlays.js"></script>

anyways thanks Moak!! it really helped.

like image 32
Professor Ez Avatar answered Nov 15 '22 08:11

Professor Ez