如何在其他表单元素中使用Google地图数据? [英] How do I use Google map data in other form elements?

查看:82
本文介绍了如何在其他表单元素中使用Google地图数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从地图获取Google地图坐标并自动填充另一个表单元素?

这是我的表单: http://www.barbadosphonebook.com/list-your-business-for-free/ 。底部有一个Google地图,点击后显示坐标。



我的地图代码:



<$ p $我喜欢它也用下面的坐标数据填充下面的元素。 p> < script type =text / javascript
src =http://maps.google.com/maps/api/js?sensor=true>
< / script>
< script type =text / javascript>
函数initialize(){
var latlng = new google.maps.LatLng(13.175771,-59.556885);
var myOptions = {
zoom:10,
center:latlng,
navigationControl:true,
mapTypeControl:true,
scaleControl:true,
mapTypeId:google.maps.MapTypeId.HYBRID
};
var map = new google.maps.Map(document.getElementById(map_canvas),myOptions);
//
var contentString ='< strong>复制括号内的数字< / strong>< br />';
google.maps.event.addListener(map,'click',function(event){
new google.maps.InfoWindow({position:event.latLng,content:contentString + event.latLng.toString ()}).open(map);
});
}
< / script>


解决方案

您可以尝试将地图点击侦听器更改为:

  google.maps.event.addListener(地图,'点击',功能(事件){
新的谷歌。 maps.InfoWindow({position:event.latLng,content:contentString + event.latLng.toString()}).open(map);
$('.ginput_container input').val(event.latLng.toString ());
});


How do I take Google map coordinates from the map and automatically populate another form element?

This is my form: http://www.barbadosphonebook.com/list-your-business-for-free/. At the bottom there is a Google map which, on-click, displays the coordinates. I would love it to also populate the element below with the coordinate data.

My map code:

<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=true">
</script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(13.175771, -59.556885);
var myOptions = {
  zoom: 10,
  center: latlng,
  navigationControl: true,
  mapTypeControl: true,
  scaleControl: true,
  mapTypeId: google.maps.MapTypeId.HYBRID
};
var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
//
var contentString = '<strong>Copy the numbers between the brackets</strong><br />';
 google.maps.event.addListener(map, 'click', function(event) {
 new google.maps.InfoWindow ( { position: event.latLng, content: contentString+event.latLng.toString() } ).open(map);
});
}
</script>

解决方案

You could try changing your map click listener to this:

google.maps.event.addListener(map, 'click', function(event) {
  new google.maps.InfoWindow ( { position: event.latLng, content: contentString+event.latLng.toString() } ).open(map);
  $('.ginput_container input').val(event.latLng.toString());
}); 

这篇关于如何在其他表单元素中使用Google地图数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆