将搜索附近的侧板添加到自定义谷歌地图
Adding Search Nearby Side Panel To Custom Google Map
我很难将Google Places API与Google Map API集成在一起。
我有以下自定义代码为自定义样式的地图工作。然而,我试图添加搜索附近餐馆、酒吧等的部分不起作用。我一直在关注并阅读本页上的文档https://developers.google.com/maps/documentation/javascript/places#TextSearchRequests试着去理解,这是有效的。我希望在我的地图上有真正的侧板。谢谢
<script>
window.onload = function () {
var styles = [
{
featureType: 'water',
elementType: 'all',
stylers: [
{ hue: '#7da6d3' },
{ saturation: 8 },
{ lightness: -13 },
{ visibility: 'on' }
]
},{
featureType: 'landscape.man_made',
elementType: 'all',
stylers: [
{ hue: '#ffffff' },
{ saturation: -100 },
{ lightness: 100 },
{ visibility: 'on' }
]
},{
featureType: 'road',
elementType: 'all',
stylers: [
{ hue: '#7e90ad' },
{ saturation: -78 },
{ lightness: -8 },
{ visibility: 'simplified' }
]
},{
featureType: 'poi.park',
elementType: 'all',
stylers: [
{ hue: '#83cca5' },
{ saturation: -3 },
{ lightness: -16 },
{ visibility: 'simplified' }
]
},{
featureType: 'poi.school',
elementType: 'all',
stylers: [
{ hue: '#dddddd' },
{ saturation: -100 },
{ lightness: 22 },
{ visibility: 'on' }
]
},{
featureType: 'poi.place_of_worship',
elementType: 'all',
stylers: [
{ hue: '#dddddd' },
{ saturation: -100 },
{ lightness: 11 },
{ visibility: 'simplified' }
]
},{
featureType: 'poi.business',
elementType: 'geometry',
stylers: [
{ hue: '#96A6C5' },
{ saturation: 16 },
{ lightness: -20 },
{ visibility: 'on' }
]
},{
featureType: 'transit',
elementType: 'geometry',
stylers: [
{ hue: '#7da6d3' },
{ saturation: 49 },
{ lightness: -12 },
{ visibility: 'on' }
]
}
];
var options = {
mapTypeControlOptions: {
mapTypeIds: ['Styled']
},
center: new google.maps.LatLng(39.9534988, -75.1748003),
zoom: 16,
disableDefaultUI: false,
mapTypeId: 'Styled'
};
var div = document.getElementById('googleMap');
var map = new google.maps.Map(div, options);
var building = {lat: 39.9534988, lng: -75.1748003};
var image = 'images/marker.jpg';
var marker = new google.maps.Marker({
position: building,
map: map,
icon: image
});
var styledMapType = new google.maps.StyledMapType(styles, { name: '1919 Market' });
map.mapTypes.set('Styled', styledMapType);
}
var request = {
location: building,
radius: '500',
query: 'restaurant'
};
var service = new google.maps.places.PlacesService(map);
service.radarSearch(request, callback);
</script>
查看您的代码,似乎有很多事情需要修复。对于初学者来说,我建议你需要在这里举一个完整的例子,只需修改它以包含你想要的定制。
注意:不要使用window.onload,而是使用脚本中的callback属性来指定在api准备好使用后将调用的函数。(请参阅下面代码中的initMap)。
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&signed_in=true&libraries=places&callback=initMap" async defer></script>
更新:
你可能需要学习Google Places API来实现你想要的目标。下面是一个关于地点搜索工作原理的示例。
相关文章:
- 表达式引擎扩展开发-向呈现的条目添加自定义javascript
- 添加自定义标记以自动完成
- 微笑时间轴小部件添加自定义字段
- 在验证器中添加自定义规则以检查<ul>具有元素
- 在log4javascript中添加自定义日志级别
- 向ASP控件添加自定义事件
- 在“添加自定义按钮”旁边添加自定义按钮;添加到CART”;WooCommerce的按钮
- 在标记mapbox.js上添加自定义图标
- 如何使用inlineformset_factory添加自定义字段属性
- 如何在 Rails 应用程序中向 Galleria 添加自定义描述
- 使用原型对象向javascript对象添加自定义属性和方法的建议
- WordPress,添加自定义JS和Foundation JS
- 如何在wooccommerce脚本之后添加自定义java脚本
- Wordpress:添加自定义HTML文件
- 在jqGrid中的行中添加自定义按钮
- 如何在联系人表单7 Wordpress中添加自定义javascript函数
- 如何在自定义帖子类型中添加自定义字段
- 如何使用Google Analytics添加自定义事件跟踪
- 如何在Javascript中向存储类添加自定义方法
- 如何向AlloyUI表单生成器添加自定义属性