Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google maps drag and drop objects into google maps from outside the Map

i'm working on a project and i need a help concerning how to drag and drop objects from outside the map into it. I tried multitude of examples but i didn't find the solution so if you can just give a sample of code to help and thanks .

like image 751
user379228 Avatar asked Apr 01 '11 08:04

user379228


People also ask

Can you integrate with Google Maps?

Whether a static or interactive map, mobile or browser-based, with the Google Maps Platform you can integrate customizable maps into shops, websites, apps, and business software.


1 Answers

Check if this is more or less what you wanted ( you will need to provide a small icon file to be dragged - update file name acorrdingly in the source). Just to mention the shelf with icons to drag can be placed anywhere also outside of the map.

<!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>

K

like image 73
kwicher Avatar answered Sep 21 '22 09:09

kwicher