Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在谷歌地图中用鼠标移动标记_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 在谷歌地图中用鼠标移动标记

Javascript 在谷歌地图中用鼠标移动标记,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我想在谷歌地图上用鼠标移动事件移动标记 <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> <title>Simple markers</title> <style> html, body, #map-ca

我想在谷歌地图上用鼠标移动事件移动标记

<!DOCTYPE html>
<html>
<head>
 <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple markers</title>
<style>
  html, body, #map-canvas {
    height: 100%;
    margin: 0px;
    padding: 0px
  }
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
function initialize() {
 var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
 var mapOptions = {
   zoom: 4,
  center: myLatlng
 }
 var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

 var marker = new google.maps.Marker({
  position: myLatlng,
  map: map,
  title: 'Hello World!'
 });
 }

 google.maps.event.addDomListener(window, 'load', initialize);

</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
下面是我在谷歌地图上添加标记的代码

<!DOCTYPE html>
<html>
<head>
 <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple markers</title>
<style>
  html, body, #map-canvas {
    height: 100%;
    margin: 0px;
    padding: 0px
  }
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
function initialize() {
 var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
 var mapOptions = {
   zoom: 4,
  center: myLatlng
 }
 var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

 var marker = new google.maps.Marker({
  position: myLatlng,
  map: map,
  title: 'Hello World!'
 });
 }

 google.maps.event.addDomListener(window, 'load', initialize);

</script>
</head>
<body>
<div id="map-canvas"></div>
</body>

简单标记
html,正文,#地图画布{
身高:100%;
边际:0px;
填充:0px
}
函数初始化(){
var mylatng=new google.maps.LatLng(-25.363882131.044922);
变量映射选项={
缩放:4,
中心:myLatlng
}
var map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
var marker=new google.maps.marker({
职位:myLatlng,
地图:地图,
标题:“你好,世界!”
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);

这是一个简单的标记示例,取自

鼠标移动时,我想用鼠标移动标记。但是我不知道怎么做

参考谷歌地图中的事件侦听器

参考谷歌地图中的事件侦听器

 var marker = new google.maps.Marker({
                position: map.getCenter(),
                map: map,
                title: 'Click to zoom'
            });

            google.maps.event.addListener(map, 'mousemove', function(e) {
                marker.setPosition(e.latLng);
            });
使用此代码,我们可以在谷歌地图上用鼠标移动标记

 var marker = new google.maps.Marker({
                position: map.getCenter(),
                map: map,
                title: 'Click to zoom'
            });

            google.maps.event.addListener(map, 'mousemove', function(e) {
                marker.setPosition(e.latLng);
            });

使用这段代码,我们可以在谷歌地图上用鼠标移动标记

如果我理解你想用鼠标移动标记的话。不一定要在
mousemouve
事件中移动它。要做到这一点,您只需将标记的
draggable
属性设置为
true

 var marker = new google.maps.Marker({
                position: map.getCenter(),
                map: map,
                title: 'Click to zoom'
            });

            google.maps.event.addListener(map, 'mousemove', function(e) {
                marker.setPosition(e.latLng);
            });
考虑以下示例:

<!DOCTYPE html>
<html>
<head>
 <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple markers</title>
<style>
  html, body, #map-canvas {
    height: 100%;
    margin: 0px;
    padding: 0px
  }
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
function initialize() {
 var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
 var mapOptions = {
   zoom: 4,
  center: myLatlng
 }
 var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

 var marker = new google.maps.Marker({
  position: myLatlng,
  map: map,
  title: 'Hello World!',
  draggable: true
 });
 }

 google.maps.event.addDomListener(window, 'load', initialize);

</script>
</head>
<body>
<div id="map-canvas"></div>
</body>

简单标记
html,正文,#地图画布{
身高:100%;
边际:0px;
填充:0px
}
函数初始化(){
var mylatng=new google.maps.LatLng(-25.363882131.044922);
变量映射选项={
缩放:4,
中心:myLatlng
}
var map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
var marker=new google.maps.marker({
职位:myLatlng,
地图:地图,
标题:“你好,世界!”,
德拉格布尔:是的
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);

要引用标记已读取的所有属性:

如果我理解,您希望能够使用鼠标移动标记。不一定要在
mousemouve
事件中移动它。要做到这一点,您只需将标记的
draggable
属性设置为
true

考虑以下示例:

<!DOCTYPE html>
<html>
<head>
 <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple markers</title>
<style>
  html, body, #map-canvas {
    height: 100%;
    margin: 0px;
    padding: 0px
  }
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
function initialize() {
 var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
 var mapOptions = {
   zoom: 4,
  center: myLatlng
 }
 var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

 var marker = new google.maps.Marker({
  position: myLatlng,
  map: map,
  title: 'Hello World!',
  draggable: true
 });
 }

 google.maps.event.addDomListener(window, 'load', initialize);

</script>
</head>
<body>
<div id="map-canvas"></div>
</body>

简单标记
html,正文,#地图画布{
身高:100%;
边际:0px;
填充:0px
}
函数初始化(){
var mylatng=new google.maps.LatLng(-25.363882131.044922);
变量映射选项={
缩放:4,
中心:myLatlng
}
var map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
var marker=new google.maps.marker({
职位:myLatlng,
地图:地图,
标题:“你好,世界!”,
德拉格布尔:是的
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);

要引用标记已读取的所有属性:

它没有鼠标移动事件它没有鼠标移动事件您确定没有使标记可拖动吗?var marker=new google.maps.marker({position:mylatng,map:map,title:'Hello World!',draggalbe:true});你确定没有按你的要求拖动标记吗?var marker=new google.maps.marker({position:mylatng,map:map,title:'Hello World!',draggalbe:true})
google.maps.Marker.setPosition
有以下签名:
setPosition(latlng:latlng)
。它不以mas作为参数。在您的示例中,地图将被忽略!那么,你回答了你自己的问题?这是你真正想要的吗?我可以知道你想要哪个应用程序吗?你想实现什么?就是问一个问题,然后自己回答。
google.maps.Marker.setPosition
有这样一个签名:
setPosition(latlng:latlng)
。它不以mas作为参数。在您的示例中,地图将被忽略!那么,你回答了你自己的问题?这是你真正想要的吗?我可以知道你想要哪个应用程序吗?你想实现什么?就是问一个问题,然后自己回答