如何直接从谷歌地图而不是地点获取对象
How can I get objects directly from Google Maps, not Places
我想获取地图对象(机场大门(的坐标。
我不能用Places API做这件事,因为门不是Places对象。
如果你打开maps.google.com并键入SFO Gate 27,它不会找到它,但如果你键入SFO,按Enter键,然后键入Gate 27。你会找到正确的位置。
所以,我的问题是,如何使用JS SDK或HTTP请求找到这样的地方?
使用地理编码器。
var geocoder;
var map;
function initialize() {
map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom: 5,
center: new google.maps.LatLng(10, 10)
});
geocoder = new google.maps.Geocoder();
// Bind click event listener for search button
document.getElementById("search").addEventListener('click', codeAddress, false);
// Bind key-up event listener for address field
document.getElementById("address").addEventListener('keyup', function (event) {
// Check the event key code
if (event.keyCode == 13) {
// Key code 13 == Enter key was pressed (and released)
codeAddress();
}
});
}
function codeAddress() {
// Get address and geocode
var address = document.getElementById("address").value;
geocoder.geocode({
'address': address
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
// Center map on result bounds
map.fitBounds(results[0].geometry.bounds);
// Place marker on map
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
initialize();
JSFiddle演示
相关文章:
- 从ajax请求中获取javascript对象
- 通过字符串获取JSON对象
- 如何在angular中获取json对象的名称
- 如何使用angular获取json对象的名称
- 获取一个对象´s属性的名称使用字符串
- 正在从嵌套值获取父对象
- 获取js对象键的值
- 获取原型对象的名称
- 如何从给定的代码中获取JSON对象
- 了解如何在数组中获取特定对象
- 获取整数对象属性名称的最小值和最大值
- 从Angular Scope中的Array中获取所有对象
- 在Javascript函数中获取Java对象属性
- 如何在JQUERY中从HTML文档中获取XML对象
- Backbone集合:如何从API中获取特定对象以放置在模型中
- 基于单个属性从数组中获取唯一对象
- 获取JSON对象中数组的长度
- 尝试获取每个对象的总和
- 正在尝试获取非对象php-DOM的属性
- 如何从HTML元素中获取Javascript对象