首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >来自Google地理定位的数组长度(Ionic)

来自Google地理定位的数组长度(Ionic)
EN

Stack Overflow用户
提问于 2017-10-24 02:15:08
回答 1查看 89关注 0票数 1

有人能指点我正确的语法方向来返回Google搜索结果的值吗?就像我的搜索返回了5个位置,我想从我的数组中提取5的值,并在我的应用程序中显示该信息“5个位置已经找到了!”我已经设法得到了附近的一张名单。但我不知道如何获得价值。

现在,我使用这段代码访问Google站点搜索结果的数组。

代码语言:javascript
运行
复制
goToDirectionPage(index){

      console.log(this.places);
      console.log("index" + index);
      let selectedPlace = this.places[index].geometry.location;

      console.log(selectedPlace);

      this.navCtrl.push(DirectionPage, {
        origin: this.currentLocation,
        destination: selectedPlace

      });
    }

这是Google地名搜索的代码

代码语言:javascript
运行
复制
import { Component} from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';

/**
 * Generated class for the DirectionPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

declare var google;

@Component({
  selector: 'page-direction',
  templateUrl: 'direction.html',
})
export class DirectionPage {

  origin: any;
  destination: any;
  map: any;


  constructor(public navCtrl: NavController, public navParams: NavParams) {
    this.origin = navParams.get('origin');
    this.destination = navParams.get('destination');
    this.map = navParams.get('map');
  }

  ionViewDidLoad() {
    this.calculateRoute();

    console.log('ionViewDidLoad DirectionPage');
  }

  calculateRoute(){
    let mapOptions = {
      center: this.origin,
      zoom: 10,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }

    this.map = new google.maps.Map(document.getElementById("directionMap"), mapOptions);

    let directionsService = new google.maps.DirectionsService();
    let directionsDisplay = new google.maps.DirectionsRenderer();

    directionsDisplay.setMap(this.map);

    let request = {
      origin: this.origin,
      destination: this.destination,
      travelMode: google.maps.TravelMode.DRIVING
    };

    directionsService.route(request, function(response, status){
      if(status == google.maps.DirectionsStatus.OK){
        directionsDisplay.setDirections(response);
        directionsDisplay.setPanel(document.getElementById('directionPanel'));
      }else{
        console.warn(status);
      }
    });

  }


}

期望结果

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-13 01:27:43

在places.html中

代码语言:javascript
运行
复制
    <ion-card>
       <ion-item ng-if = "places" >
       Places Found: {{places?.length}}
      </ion-item>
     </ion-card>  

    <ion-card id="result"> </ion-card>
      <button ion-item *ngFor = "let place of places; let i = index" (click)="goToDirectionPage(i)">
       {{place.name}} + <br/> {{place.vicinity}} <br /> Average Rating: {{place.rating}}
      </button>
    </ion-list>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46901173

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档