jquery – google地图将地图上的对象拖放到谷歌地图中

前端之家收集整理的这篇文章主要介绍了jquery – google地图将地图上的对象拖放到谷歌地图中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在开展一个项目,我需要一个关于如何从地图外拖放对象的帮助.我尝试了大量的例子,但是我没有找到解决方案,所以如果你可以给出一个代码示例来帮助和感谢.

解决方法

检查是否或多或少是你想要的(你需要提供一个小图标文件被拖动 – 在源文件中更新文件名).只要提到带有图标拖动的货架,就可以放置在地图外面.
<!DOCTYPE html>
<html>
<head>
<Meta name="viewport" content="initial-scale=1.0,user-scalable=no" />
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
html { height: 100% }
body{ height: 100%; margin: 0px; padding: 0px;}
#map_canvas { height: 100% }
#shelf{position:fixed; top:10px; left:500px; height:100px;width:200px;background:white;opacity:0.7;}
#draggable {position:absolute;top:10px,left:10px; width: 30px; height: 30px;z-index:1000000000;}
</style>
<script type="text/javascript">
$(document).ready(function() {
$("#draggable").draggable({helper: 'clone',stop: function(e) {
    var point=new google.maps.Point(e.pageX,e.pageY);
    var ll=overlay.getProjection().fromContainerPixelToLatLng(point);
    placeMarker(ll);
    }
});
});
</script>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
var $map;
var $latlng;
var overlay;
function initialize() {
var $latlng = new google.maps.LatLng(66.5,25.733333);
var myOptions = {
  zoom: 3,center: $latlng,mapTypeId: google.maps.MapTypeId.ROADMAP,mapTypeControlOptions: {
    style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,position: google.maps.ControlPosition.TOP_LEFT },zoomControl: true,zoomControlOptions: {
    style: google.maps.ZoomControlStyle.LARGE,position: google.maps.ControlPosition.LEFT_TOP
},scaleControl: true,scaleControlOptions: {
    position: google.maps.ControlPosition.TOP_LEFT
},streetViewControl: false,panControl:false,};
$map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);

overlay = new google.maps.OverlayView();
overlay.draw = function() {};
overlay.setMap($map);
} 
function placeMarker(location) {
  var marker = new google.maps.Marker({
  position: location,map: $map,icon:'spring-hot.png'
  });

}
</script>
</head>
<body onload="initialize()">
    <div id="map_canvas">    </div>
<div id='shelf'>Drag the image<br/><img id="draggable" src='spring-hot.png'/><div>
</body>
</html>

ķ

原文链接:https://www.f2er.com/jquery/180420.html

猜你在找的jQuery相关文章