任何人都可以帮我使用Google API,它可以根据Pincode作为输入获取所有周边信息。
基本上,如果我输入Pincode号码,那么API应该返回所有购物中心,桥梁,医院,酒店等。我希望能够将这些信息存储在数据库中。
请分享您的想法。
答案 0 :(得分:1)
我希望以下代码能为您提供帮助。它能做什么? 1.从输入字段中取出您的密码,对其进行地理编码。 2.从地理编码的结果来看,它适用于地点api,以找到半径500米附近的商店。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Geocoding service</title>
<style>
html, body, #map-canvas {
height: 800px;
widows: 700px;
margin: 0px;
padding: 0px
}
#panel {
position: absolute;
top: 5px;
left: 50%;
margin-left: -180px;
z-index: 5;
background-color: #fff;
padding: 5px;
border: 1px solid #999;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script>
<script>
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var mapOptions = {
zoom: 8,
center: latlng
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}
function codeAddress() {
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
var request = {
location: results[0].geometry.location,
radius: '500',
types: ['store']
}; //500 meters and stores only
var service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
} else {
alert('Geocode was not successful for the following reason: ' + status);
}});}
function callback(results, status) {
console.log(status, results);
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
//createMarker(results[i]);
var marker = new google.maps.Marker({
map:map,
position: place.geometry.location
})
}}}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="panel">
<input id="address" type="textbox" value="452009">
<input type="button" value="Geocode" onclick="codeAddress()">
</div>
<div id="map-canvas"></div></body></html>
如果您有任何疑问,请发表评论,我们可以继续处理。
问候,
Suyash