代码之家  ›  专栏  ›  技术社区  ›  Amit Gandole

如何从google地图API的URL中获取地理代码数据,而不是在IONIC WebAPP中添加地理代码函数?

  •  0
  • Amit Gandole  · 技术社区  · 7 年前

    好的,所以基本上我用一个离子型的本地人来获取我输入位置的lat和液化天然气。但是由于本地人只适用于Android和IOS,所以我想要一些API之类的东西,可以在任何平台上使用,并且可以返回正确的位置。 在搜索之后,我找到了Google的URL Api

    http://maps.google.com/maps/api/geocode/json?address='+ term +'CA&sensor=false
    

    所以我试着用这个。但通过我的代码调用它。它提供未定义的输入。

    这是我的代码:

    getLocation(term){
    
    
    return new Promise(resolve => {
      this.http.get('http://maps.google.com/maps/api/geocode/json?address='+ term +'CA&sensor=false')
        .map(res => res.json())
        .subscribe(data => {
          console.log(data.results[0]);
          resolve(data);
        });
    });
    

    }

    另外,我从另一个函数调用它,比如:

        initMap() {
    
            this.getLocation('seattle');
            //Also I want to use lat lang here. Please provide proper way to get that.
    
    }
    

    如何在IONIC中使用那个URL Api?请不要提供任何使用本机的解决方案,因为我想将其部署在只有浏览器平台上。

    0 回复  |  直到 7 年前