我可以使用 google 地图图钉来填充我网页上的表单吗?
Can I use google maps pins to populate a form on my webpage?
我有一个包含 600 多个地图标记 的数据库,其中包含 longitude
和 latitude
以及供客户使用的所有适用信息。
我需要创建一些东西,让我可以点击地图中的图钉标记,然后点击该图钉上的任何数据 (phone 号码、邮政编码、地址等) 从数据库中的那个 pin 中提取并添加到表单中。
我可以从 google 地图中提取数据以填充网页上的表格吗?
你应该能找到有用的东西here:
您需要为此执行某些步骤。
从 Google 开发人员生成密钥:
Link = 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>
我有一个包含 600 多个地图标记 的数据库,其中包含 longitude
和 latitude
以及供客户使用的所有适用信息。
我需要创建一些东西,让我可以点击地图中的图钉标记,然后点击该图钉上的任何数据 (phone 号码、邮政编码、地址等) 从数据库中的那个 pin 中提取并添加到表单中。
我可以从 google 地图中提取数据以填充网页上的表格吗?
你应该能找到有用的东西here:
您需要为此执行某些步骤。
从 Google 开发人员生成密钥:
Link = 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>