1

我正在尝试使用 Java 中的附近搜索来返回符合过滤要求的地点列表。并说在被退回的企业中,有 3 家企业的名称如下: Harbour food center City Restaurants Harbour & City Foods

如何使用关键字过滤结果,以便只返回同时包含 Harbour 和 City 的地方?我尝试在关键字中使用“Harbour&City”,但这不起作用。注意我不能使用文本搜索,因为它不会重新调整我添加的位置。

public PlacesList performNearbySearch(double lat, double lng, String keyword, String    types) throws Exception {
  try {
   System.out.println("Perform Search ....");
  System.out.println("-------------------");
  HttpRequestFactory httpRequestFactory = createRequestFactory(HTTP_TRANSPORT);
  HttpRequest request = httpRequestFactory.buildGetRequest(new GenericUrl(PLACES_NEARBY_URL));
  request.getUrl().put("key", API_KEY);
  request.getUrl().put("location", lat+","+lng);
  request.getUrl().put("keyword", "Harbour&City");
  request.getUrl().put("types", types);
  request.getUrl().put("radius", "2000");
  request.getUrl().put("sensor", "false");

  PlacesList places = request.execute().parseAs(PlacesList.class);
  System.out.println("STATUS = " + places.status);
  for (Place place : places.results) {
  System.out.println(place);
  }
  return places;

 } catch (HttpResponseException e) {
 System.err.println(e.getMessage());
 return null;
 }
}
4

3 回答 3

0

您可以使用下面的脚本来查看它,

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!-- Consider adding a manifest.appcache: h5bp.com/d/Offline -->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
  <meta charset="utf-8">

  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

  <title>What's Near Me</title>
  <meta name="description" content="Find what's near you">

  <!-- Mobile viewport optimized: h5bp.com/viewport -->
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <link rel="stylesheet" href="http://www.gurchet-rai.net/places/css/bootstrap.min.css">
  <link rel="stylesheet" href="http://www.gurchet-rai.net/places/css/style.css">
</head>
<body>

<div class="navbar navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container">
            <a class="brand" href="#">NearMe</a>
            <!--
            <button class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">                        
                <i class="icon-chevron-down"></i>
            </button> -->
            <form id="search" class="navbar-form form-search" action="#">                    
                <div class="input-append">
                    <input id="query" type="text" class="search-query" placeholder="Where to?" >
                    <button type="submit" class="btn"><i class="icon-search"></i></button>

                </div>       
                <!--
                <div class="nav-collapse" style="float: right">
                    <div id="view-type" class="btn-group pull-right" data-toggle="buttons-radio">
                        <button id="map-view" type="button" class="btn active">Map View</button>
                        <button id="list-view" type="button" class="btn">List View</button>
                    </div>
                </div>
                -->
            </form>
        </div>
    </div>
</div>

<div id="content">
<div id="padded-content">
<div id="location-details"></div>
<div id="map_canvas" style="width: 100%; height: 100%"></div>
</div>
</div>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript" src="http://www.gurchet-rai.net/places/css/bootstrap.min.css"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>

<script type="text/javascript">

        var loc;
        var map;
        var service;
        var infoWindow;
        var overlays = [];
        var resultList = [];
        var isMobile = $(window).width < 767;

                        loc = new window.google.maps.LatLng(29.750824, -95.362151);
                        //new google.maps.LatLng(coords.latitude, coords.longitude);
                        map = new google.maps.Map(document.getElementById("map_canvas"), {
                            mapTypeId: google.maps.MapTypeId.ROADMAP,
                            mapTypeControl: false,
                            center: loc,
                            zoom: 13
                        });  

                        service = new google.maps.places.PlacesService(map);                        
                        infoWindow = new google.maps.InfoWindow();            


        function plotResultList(){
            var iterator = 0;                  
            for(var i = 0; i < resultList.length; i++){
                setTimeout(function(){
                    var lat = resultList[iterator].geometry.location.Za;
                    var lng = resultList[iterator].geometry.location.Ya;
                    var name = resultList[iterator].name;
                    var addr = resultList[iterator].formatted_address;
                    var reference = resultList[iterator].reference;

                     var image = {
                                    url:resultList[iterator].icon,
                                    size: new google.maps.Size(71, 71),
                                    origin: new google.maps.Point(0, 0),
                                    anchor: new google.maps.Point(17, 34),
                                    scaledSize: new google.maps.Size(25, 25)
                                  };


            var marker = new google.maps.Marker({
                        position: resultList[iterator].geometry.location,
                        map: map,
                        title: name,
                        icon: image,
                        animation: isMobile? 'undefined' : google.maps.Animation.DROP
                    });
                    overlays.push(marker);

                    google.maps.event.addListener(marker, 'click', function() {
                        infoWindow.close();
                        var request = {
                            reference: reference
                        };

                        service.getDetails(request, function(place, status){
                            var content = "<h6>" + name + "</h6>";
                            if(status == google.maps.places.PlacesServiceStatus.OK){    
                                if(typeof place.rating !== 'undefined'){
                                    var badgeType = '';
                                    if (place.rating < 2){
                                        badgeType = 'badge-important';
                                    } else if (place.rating >= 2 && place.rating <= 3){
                                        badgeType = 'badge-warning';
                                    } else {
                                        badgeType = 'badge-success';
                                    }
                                    content += "<p><small>Rating: <span class='badge " + badgeType + "'>" + place.rating + "</span></small></p>"; 
                                }    

                                if(typeof place.formatted_address !== 'undefined'){
                                    content += "<br><small>" + place.formatted_address + "</small>";
                                }

                                if(typeof place.formatted_phone_number !== 'undefined'){
                                    content += "<br><small><a href='tel:" + place.formatted_phone_number + "'>" + place.formatted_phone_number + "</a></small>";                                 
                                }

                                if(typeof place.website !== 'undefined'){
                                    content += "<br><small><a href='" + place.website + "'>website</a></small>";

                                }
                            }                            

                            infoWindow.setContent(content);
                            infoWindow.open(map, marker);         
                        });
                    });
                    iterator++;
                }, isMobile? 0: (i * 75));
            }
        }

            var query = 'airports,hospitals,atm';//$('#query').val();
            //alert(map);         
            var request = {
                location: map.getCenter(),
                radius: '5000',
                query: query            
            };


            service.textSearch(request, function(results, status, pagination){
                for(var i = 0; i < overlays.length; i++){                   
                    overlays[i].setMap(null);
                }
                resultList.length = 0;
                overlays.length = 0;
                if (status == google.maps.places.PlacesServiceStatus.OK) {
                    resultList = resultList.concat(results);
                    plotResultList();
                }
            });

</script>
</body>
</html>
于 2013-10-12T19:12:03.050 回答
0

使用 Google place API,进行布尔搜索似乎是这样的:

var request = {
            location: /*your location*/,
            radius: /*your radius*/,              
            keyword: "(cinema) OR (theater)"           
        };
于 2014-05-28T12:04:22.293 回答
0

尝试使用types=hospital|pharmacy|doctor

注意:使用多个参数将继续返回结果,直到2017 年 2 月 16 日,但我们不建议在搜索请求中使用多个类型。在该日期之后,将不再支持具有多种类型的请求。

于 2016-06-07T12:49:46.450 回答