我目前在我的应用中集成了Google地图API,并希望包含Google地方(https://developers.google.com/maps/documentation/javascript/examples/place-search)。我已经到了地理位置,但从那时起,我有点失落。我想在附近搜索“超市”,但我正在努力将其转换为Typescript / angular。
我目前拥有的启用地理位置的代码是
loadMap(){
Geolocation.getCurrentPosition().then((position) => {
let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
let mapOptions = {
center: latLng,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);
}, (err) => {
console.log(err);
});
}
addMarker(){
let marker = new google.maps.Marker({
map: this.map,
animation: google.maps.Animation.DROP,
position: this.map.getCenter()
});
let content = "<h4>You are here!</h4>";
this.addInfoWindow(marker, content);
}
addInfoWindow(marker, content){
let infoWindow = new google.maps.InfoWindow({
content: content
});
google.maps.event.addListener(marker, 'click', () => {
infoWindow.open(this.map, marker);
});
}
如果有人可以帮我整合/转换地点api到我当前的代码中,那将非常感激。
答案 0 :(得分:0)
我认为这篇文章会对你有所帮助。 https://ampersandacademy.com/tutorials/ionic-framework-version-2/google-map-places-search-api-example
它使用打字稿谷歌地图库。
npm install @types/googlemaps --save-dev
搜索位置使用
new google.maps.places.AutocompleteService();