本文介绍了按纬度和经度格式更新Google地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我正在构建一个HTML页面,其中我需要一个Google Map和一个由两个纬度和经度字段组成的简单表单。 <!DOCTYPE html>
< html>
< head>
< meta name =viewportcontent =initial-scale = 1.0,user-scalable = no/>
< style type =text / css>
html {height:100%}
body {height:100%;保证金:0; padding:0}
#map-canvas {height:100%}
< / style>
< script type =text / javascript
src =https://maps.googleapis.com/maps/api/js?key=AIzaSyA_0qaGwK5ZWdKYXHRlJ-05CI_geHWo6v4&sensor=false>
< / script>
< script type =text / javascript>
函数initialize(){
var mapOptions = {
center:new google.maps.LatLng(-34.397,150.644),
zoom:8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById(map-canvas),
mapOptions);
}
google.maps.event.addDomListener(window,'load',initialize);
< / script>
< / head>
< body>
< div id =map-canvas/>
< / body>
< / html>
所以这是嵌入地图的代码,从我必须想到的我需要创建
center:new google.maps.LatLng(-34.397,150.644)
并随时更新它,只要按下更新按钮或提交按钮即可。我知道如何创建一个表单,但不知道如何在上面的代码中使用。
任何帮助将不胜感激。
解决方案
<!DOCTYPE html>
< html>
< head>
< title>简易地图< /标题>
< meta name =viewportcontent =initial-scale = 1.0,user-scalable = no>
< meta charset =utf-8>
< style>
html,body,#map-canvas {
margin:0;
padding:0;
身高:100%;
}
< / style>
< script src =https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false>< / script>
< script>
var map;
函数initialize(){
var mapOptions = {
zoom:8,
center:new google.maps.LatLng(-34.397,150.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
}
google.maps.event.addDomListener(window,'load',initialize);
function pan(){
var panPoint = new google.maps.LatLng(document.getElementById(lat).value,document.getElementById(lng).value);
map.panTo(panPoint)
}
< / script>
< / head>
< body>
< label> lat< / label>< input type =textid =lat/>
< br />
< label> lng< / label>< input type =textid =lng/>
< input type =buttonvalue =updateCenteronclick =pan()/>
< div id =map-canvas>< / div>
< / body>
< / html>
So I am building a HTML page, in which i need a Google Map and a simple form which consists of two fields latitude and longitude.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { height: 100% }
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA_0qaGwK5ZWdKYXHRlJ-05CI_geHWo6v4&sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"/>
</body>
</html>
So this is the code to embed a map, from what i have to figured that I need to create a form which change the values of this line :
center: new google.maps.LatLng(-34.397, 150.644)
and updates it whenever I press the update button or submit button. I know how to create a form but don't know how exactly to use in the above code.
Any help would be appreciated.
解决方案
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
margin: 0;
padding: 0;
height: 100%;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var map;
function initialize() {
var mapOptions = {
zoom: 8,
center: new google.maps.LatLng(-34.397, 150.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
function pan() {
var panPoint = new google.maps.LatLng(document.getElementById("lat").value, document.getElementById("lng").value);
map.panTo(panPoint)
}
</script>
</head>
<body>
<label>lat</label><input type="text" id="lat" />
<br/>
<label>lng</label><input type="text" id="lng" />
<input type="button" value="updateCenter" onclick="pan()" />
<div id="map-canvas"></div>
</body>
</html>
这篇关于按纬度和经度格式更新Google地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!