【问题标题】:Google Places API - Nearby search (Ionic 2)Google Places API - 附近搜索(Ionic 2)
【发布时间】:2017-02-20 10:32:27
【问题描述】:

我目前已在我的应用程序中集成了 Google 地图 api,并且还希望包含 google 地点 (https://developers.google.com/maps/documentation/javascript/examples/place-search)。我已经到了地理位置,但从那时起我有点迷路了。我想在附近搜索“超市”,但我正在努力将其转换为 Typescript/angular。

我目前拥有的启用地理定位的代码是

加载地图(){

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 集成/转换到我当前的代码中,将不胜感激。

【问题讨论】:

标签: angularjs typescript ionic-framework ionic2 google-places-api


【解决方案1】:

我认为这篇文章会对你有所帮助。 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(); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多