首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在google places中选择自动完成结果

无法在google places中选择自动完成结果
EN

Stack Overflow用户
提问于 2016-02-20 10:16:38
回答 2查看 2.5K关注 0票数 4

我正在使用google places API在我的离子/科尔多瓦,角度为基础的移动应用程序在安卓平台。

我可以使用API从文本字段值中获取搜索结果,但是当我通过单击其中一个搜索结果来选择一个选项时,文本框仍然是空的。

但是当我按下并将搜索结果选项保持在2-3秒时,该选项将被选中。

这在我看来很奇怪,但它正在发生。

place_changed event不会在快速点击时触发。

我真的不知道这个问题的原因是什么?我已经尝试了Faskclick.j,以消除300毫秒,但这是无效的,虽然我认为这个问题与300毫秒的延迟无关。

我的代码:

代码语言:javascript
复制
 function initialize() {
    var autocomplete = new google.maps.places.Autocomplete(input, options);
};   

请帮帮我。

EN

回答 2

Stack Overflow用户

发布于 2016-02-21 08:49:26

在下面的示例中,我一起使用了ngMap角-谷歌-位置-自动完成

希望能帮上忙。

代码语言:javascript
复制
angular.module('app', ['ionic', 'google.places', 'ngMap'])

.controller('MapCtrl', ['$scope', 'NgMap',
	function ($scope, NgMap) {

		$scope.location = null;

		NgMap.getMap().then(function (map) {
			console.log("getMap");
			$scope.map = map;
		});
		
		$scope.$on('g-places-autocomplete:select', function(event, place) {
			console.log('new location: ' + JSON.stringify(place));
			$scope.data = {
				lat: place.geometry.location.lat(),
				lng: place.geometry.location.lng()
			};
			$scope.map.setCenter(place.geometry.location);
			console.log($scope.data);
		});
	}
]);
代码语言:javascript
复制
.map {
  width: 100%;
  height: 500px !important;
}
代码语言:javascript
复制
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
  <title></title>

  <script src="https://maps.google.com/maps/api/js?libraries=visualization,drawing,geometry,places"></script>
  <link href="http://code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
  <script src="http://code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
  <script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>
  <script src="https://rawgit.com/kuhnza/angular-google-places-autocomplete/master/dist/autocomplete.min.js"></script>
  <link href="https://rawgit.com/kuhnza/angular-google-places-autocomplete/master/dist/autocomplete.min.css" rel="stylesheet">
  <link href="style.css" rel="stylesheet">
  
  <script src="app.js"></script>
</head>

<body ng-app="app" ng-controller="MapCtrl">
  <ion-pane>
<ion-header-bar class="bar-positive">
  <h1 class="title">Ionic map</h1>
</ion-header-bar>
<ion-content class="has-header padding">
  
  <div class="item item-input-inset">
      <label class="item-input-wrapper">
        <input type="text" g-places-autocomplete ng-model="location" placeholder="Insert address/location"/>
      </label>
      <button ng-click="location = ''" class="button ion-android-close input-button button-small" ng-show="location"></button>
  </div>
  <ng-map zoom="6" class="map">
    <marker position="{{data.lat}}, {{data.lng}}"></marker>
  </ng-map>
</ion-content>
  </ion-pane>
</body>

</html>

票数 2
EN

Stack Overflow用户

发布于 2016-02-21 12:50:17

我没有找到它的解决方案,但是https://github.com/stephjang/placecomplete是一个很好的插件,因为它可以实现:)

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

https://stackoverflow.com/questions/35521810

复制
相关文章

相似问题

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