English 中文(简体)
如何在像谷歌地图这样的网站上自动填满/封顶?
原标题:How to auto-complete/suggest places (with address) on my website like on Google maps?

I am working a Yelp-like project that associates reviews to places. Yet, we don t have any database of places and we d like to leverage a third-party api. We d like to start with a auto-complete search box like on Google Maps. For example, the user enters "tamar" and it suggests "Tamarine Restaurant, Palo Alto, CA, United States". 1) is it possible? what third party api would you use? Is Google maps the best?

Once the results are returned, the user selects one place and will leave a review. 2) how would you associate that review to that specific place in the DB? My concern is if later on we change api provider, that we can still associate our reviews to the new api places.

Thank you SO MUCH! Any suggestion would help. Fab

问题回答

这将产生汽车,如果需要,也可在两个文本箱中获取lat子和长it。 最初的中心是固定的。

<head>
 <script type="text/javascript" src=" https://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js"></script>
  <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
  <script type="text/javascript">
  var map;
  var geocoder;
  geocoder = new google.maps.Geocoder();

  function initialize() {
var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316);
    map = new google.maps.Map(document.getElementById( map ), {
  mapTypeId: google.maps.MapTypeId.ROADMAP,
  center: pyrmont,
   zoom: 15
  });

  var input = document.getElementById( searchTextField );
  var options = {
  bounds: pyrmont,
 //types: [ establishment ]  dont mention it we need to get both bussiness andaddress
  };
  autocomplete = new google.maps.places.Autocomplete(input, options);
  }

  $(document).ready(function() {
  $("#find").click(function(){

   var address = document.getElementById("searchTextField").value;
   geocoder.geocode( {  address : address}, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {
    map.setCenter(results[0].geometry.location);
    var test = results[0].geometry.location;
    var latlang=String(test);
    latlang = latlang.substring(0, latlang.length-1);
    latlang= latlang.substr(1);
    var latlan = latlang.split(",");
    var lat = latlan[0];
    var lon = latlan[1];
    $("#latitude").val(lat);
            $("#longitude").val(lon);
      var marker = new google.maps.Marker({
           map: map,
            position: results[0].geometry.location
        });
      } else {
       alert("Geocode was not successful for the following reason: " + status);
     }
   }); 
 });
});

</script>

  <body onload="initialize();">
 <label> Type address</label>
<input type="text" id="searchTextField" style="width:500px;" />
<div id="map" style="width:500px;height:500px;"></div>
<input type="text" id="latitude"/>
<input type="text" id="longitude"/>
<input type="button" id="find"  value="Find"/>
 </body>

http://compass.webservius.com“rel=“nofollow”http://compass.webservius.com 这可以帮助。 你们可以检索美国数百万家企业的数据库(例如,用你榜样中的名牌、手法、自由度/捆绑箱等),并以XML或JSON格式收回结果(如商业名称、地址、类型等)。

对于你的问题的第二部分来说,这是很棘手的,因为对企业来说不存在“通用身份”,但通常将正常的邮政地址+商业名称结合起来,将起到足够的作用。

html

<script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>

HTML Form Input

<input id="locationName" name="locationName" type="text">

Java

 function init() {
        var input = document.getElementById( locationName );
        var autocomplete = new google.maps.places.Autocomplete(input);
    }
    google.maps.event.addDomListener(window,  load , init);




相关问题
How to decide the current point reach on google map?

How to decide the current point reach on google map? I have a list of points (pickup points) of a route that I want to show in my google map with polyline. Now i have to get the current location of ...

Topographical or relief data in Map APIs

I was wondering if anyone knew of any map APIs that offer topographical or relief data? I ve had a quick look at Google and Bing APIs, but could find nothing there. Google allow you to view a map as ...

Using maps on Windows Mobile

I m experimenting with maps on different mobile platforms. Getting Google Maps to work on Android was easy, following this tutorial. Getting the same to work on Windows Mobile is a different matter. ...

Adding a custom icon to a google map

I need a hand adding a custom icon to some Google Maps javascript. Code below for your reference: function populateMap() { var map = new GMap2(document.getElementById("map")); map.setCenter(new ...

RSS to KML Overlay

I m want to display my blog as a Google Map overlay (each post contains geotags). How can I dynamically create a KML overlay from an RSS? Or better, how can I create a loop (PHP) that would display ...

开放街道地图管理员

我需要开放Street的标记管理员。 地图,如山角地图。

热门标签