谷歌地图代码显示当前位置,并在Php:-Firefox中触摸时创建新标记
Google maps code show current location and creat new marker when touched in Php:- Firefox
我正试图让我的代码在当前位置显示一个标记,并在触摸或点击屏幕时设置一个新的标记,这就是我迄今为止所拥有的,因为我不是程序员,所以我在这个网站上创建的大部分代码都是为了工作。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Google Maps</title>
<style>
#map_canvas{
height:800px;
width:800px;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?sensor=true">
</script>
<script>
navigator.geolocation.getCurrentPosition(initialize);
var marker, map;
function initialize() {
var mapOptions = {
zoom: 14,
center: {lat: 20.58333333, lng: -100.41700278},
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
var lavaditozone = [
{lat: 20.59093056, lng: -100.433975},
{lat: 20.57652778, lng: -100.433975},
{lat: 20.57652778, lng: -100.40218611},
{lat: 20.58610278, lng: -100.4120722},
{lat: 20.59093056, lng: -100.433975}
];
var arealavadito = new google.maps.Polyline({
path: lavaditozone ,
strokeColor: '#FF0000',
strokeOpacity: 1,
strokeWeight: 10
});
arealavadito.setMap(map);
google.maps.event.addListener(map, 'click', function(event){
addMarker(event.latLng);
});
}
function addMarker(latLng){
//clear the previous marker and circle.
if(marker != null){
marker.setMap(null);
}
marker = new google.maps.Marker({
position: latLng,
map: map,
draggable:false
});
var position =latLng ;
window.document.title = position;
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas"></div>
</body>
</html>
您必须给当前位置对象初始化函数,才能获得当前位置
function initialize(curr_position) {
var map_center = new google.maps.LatLng(curr_position.coords.latitude, curr_position.coords.longitude);
var mapOptions = {
zoom: 14,
center: map_center,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
var lavaditozone = [
{lat: 20.59093056, lng: -100.433975},
{lat: 20.57652778, lng: -100.433975},
{lat: 20.57652778, lng: -100.40218611},
{lat: 20.58610278, lng: -100.4120722},
{lat: 20.59093056, lng: -100.433975}
];
var arealavadito = new google.maps.Polyline({
path: lavaditozone ,
strokeColor: '#FF0000',
strokeOpacity: 1,
strokeWeight: 10
});
arealavadito.setMap(map);
google.maps.event.addListener(map, 'click', function(event){
addMarker(event.latLng);
});
}
相关文章:
- 为什么这在IE中的工作方式与在Firefox中不同
- 触摸移动时切换到新元素
- JS可以在Chrome中工作,但不能在Firefox中工作
- createElement("a") - FireFox JavaScript
- 为什么javascript:void(0)在Firefox中不起作用
- Facebook登录按钮没有'不能在Firefox上工作
- 谷歌地图劫持了iphone's滚动(触摸事件)-如何恢复
- jpm的默认Firefox路径没有'不起作用
- 重载JS'firefox中的对象原型
- Ajax调用在Firefox中不会自动响应
- ng消息仅在触摸时显示错误,并在错误的初始显示上转换
- JS在firefox中无法正常工作
- 在 Firefox 中“解析”触摸事件
- 带有 Firefox 的 Surface Pro 3 - 具有单点触摸触发器触摸/鼠标事件,而不是滚轮事件
- 在触摸键盘外部时禁用Firefox OS键盘自动隐藏
- 谷歌地图代码显示当前位置,并在Php:-Firefox中触摸时创建新标记
- 如何确保在Firefox桌面浏览器中启用触摸事件
- 如何在Firefox Mobile (Android, Fennec 7.0.1)中检测触摸支持
- 如何/是否可以在Firefox Windows触摸桌面中创建与touchstart事件相对应的侦听器
- Firefox触摸滚动不工作