简体   繁体   English

Google Maps API v3 jQuery Mobile

[英]Google Maps API v3 jQuery Mobile

I am trying to figure out how to limit the number of markers that can be created to one. 我试图弄清楚如何将可以创建的标记数限制为一个。 Using the example code from the "other-example.html" file, the user can create multiple markers and I would like the user to be limited to one marker. 使用“ other-example.html”文件中的示例代码,用户可以创建多个标记,我希望用户只能使用一个标记。 I tried an "if" statement such as "int i; if (i<1){... i++;}" around the addMarker function and didn't have any luck. 我在addMarker函数周围尝试了“ if”语句,例如“ int i; if(i <1){... i ++;}”,但没有任何运气。 I am guessing it is something really simple to fix. 我猜这很容易解决。

http://jquery-ui-map.googlecode.com/svn/trunk/demos/other-examples.html http://jquery-ui-map.googlecode.com/svn/trunk/demos/other-examples.html

Also I am trying to find a good tutorial on using gmaps to record lat/long location data via PHP/MYSQL to a database I have already created. 我也试图找到一个很好的教程,介绍如何使用gmaps通过PHP / MYSQL将经纬度位置数据记录到已经创建的数据库中。 Specifically, how can I pass the newly created marker's lat/long info to the database and then later retrieve the coordinates to be displayed on a non-editable gmap? 具体来说,如何将新创建的标记的纬度/经度信息传递到数据库,然后在以后检索要显示在不可编辑gmap上的坐标?

I will appreciate any help I can get with these questions, I don't expect them all to be answered! 对于这些问题,我将为您提供任何帮助,我不希望所有这些问题都能得到解答!

If you're allowing users to add markers, I'd say you then make an ajax call to your PHP page, passing user ID, latitude and longitude (and anything else your DB will require). 如果您允许用户添加标记,那么我想说您然后对您的PHP页面进行ajax调用,传递用户ID,纬度和经度(以及您的数据库需要的其他任何信息)。

To prevent users adding more than 1 marker, I think you must have been on the right tracks. 为防止用户添加1个以上的标记,我认为您必须走在正确的轨道上。 I'd maybe do it like this. 我可能会这样。

var intMarkers = 0;  // make it global

$('#map_canvas').gmap().bind('init', function(event, map) {
            $(map).click( function(event) {
                intMarkers++;
                if (intMarkers === 0) {
                            $('#map_canvas').gmap('addMarker', {'position': event.latLng, 'draggable': true, 'bounds': false}, function(map, marker) {
                                $('#dialog').append('<form id="dialog'+marker.__gm_id+'" method="get" action="/" style="display:none;"><p><label for="country">Country</label><input id="country'+marker.__gm_id+'" class="txt" name="country" value=""/></p><p><label for="state">State</label><input id="state'+marker.__gm_id+'" class="txt" name="state" value=""/></p><p><label for="address">Address</label><input id="address'+marker.__gm_id+'" class="txt" name="address" value=""/></p><p><label for="comment">Comment</label><textarea id="comment" class="txt" name="comment" cols="40" rows="5"></textarea></p></form>');
                                findLocation(marker.getPosition(), marker);
                            }).dragend( function(event) {
                                var self = this;
                                findLocation(event.latLng, this);
                            }).click( function() {
                                openDialog(this);
                            });

                            // stick in an Ajax call here too
                }
            });
        });

Also the example code is using the deprecated Google Maps API 2, I'd suggest you use API 3 instead. 另外,示例代码使用的是不推荐使用的Google Maps API 2,建议您改用API 3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM