【问题标题】:Can I use google maps pins to populate a form on my webpage? [closed]我可以使用谷歌地图别针在我的网页上填充表单吗? [关闭]
【发布时间】:2015-06-22 22:46:00
【问题描述】:

我有一个包含600 多个地图标记的数据库,其中包含longitudelatitude 以及供客户使用的所有适用信息。

我需要创建一些东西,允许我单击地图中的 pin 标记,然后从该 pin 中提取附加到该 pin (电话号码、邮政编码、地址等)的任何数据在数据库中并添加到表单中。

我可以从谷歌地图中提取数据以填充网页上的表单吗?

【问题讨论】:

  • 简短的回答是“是”。我不得不输入更长的内容,因为 SO 需要它。
  • 我投票结束这个问题,因为这是一个“是”/“否”的问题。您可以自己轻松地测试它,或者您已经有部分解决方案要展示,有问题要提交给社区,然后您可以得到帮助:)
  • @kheldar 如果您在下面查看有人已经帮助解决了问题。无论如何,这不是题外话

标签: php mysql database google-maps dynamic


【解决方案1】:

您需要为此执行某些步骤。

从 Google Developer 生成密钥:

链接 = https://code.google.com/apis/console/

生成的密钥 = "GeneratedKey"

<!DOCTYPE html>
    <html>
  <head>
    <style type="text/css">
      html, body, #map-canvas { height: 100%; margin: 0; padding: 0;}
    </style>
    <script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?key=YourGenerateKeyHere">
    </script>
<script>
	
   function getLocation()
    {
	var geocoder = new google.maps.Geocoder();
	var address = document.getElementById("Location").value;
	var latitude = 0;
	var longitude = 0;
	geocoder.geocode( { 'address': address}, function(results, status) {
	if (status == google.maps.GeocoderStatus.OK) {
		latitude = results[0].geometry.location.lat();
        longitude = results[0].geometry.location.lng();
		showPosition(latitude, longitude, address);
	}
	}); 
   }
    function showPosition(latitude, longitude, address)
	{
		var mapOptions = {
          center: { lat: latitude, lng: longitude},
          zoom: 18,
		  mapTypeId: google.maps.MapTypeId.ROADMAP 
        };
        var map = new google.maps.Map(document.getElementById('map-canvas'),
            mapOptions);
		var myLatlng = new google.maps.LatLng(latitude,longitude);

		var marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title: address,
  });

		google.maps.event.addDomListener(window, 'load', initialize);
    }
     
</script>
<body>
	<input type="text" id="Location" placeholder="Type address here" />
    <button onclick="getLocation()">Click here to see map</button>
  
<div id="map-canvas"></div>
  
</body>
</html>
</html>

【讨论】:

  • 感谢您的出色回复和帮助!
【解决方案2】:

你应该能找到有用的东西here:

【讨论】:

    猜你喜欢
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多