从Google Places API服务获取基于地名、城市名称和地址的地名ID

从Google Places API服务获取基于地名、城市名称和地址的地名ID,api,google-places-api,Api,Google Places Api,我正在使用Google Places API服务()根据位置名称获取位置id。用户键入一些位置名称和相关建议,用户可以从中选择并获取位置Id。我有一个要求,我需要有三个文本框和一个按钮。用户将输入地名、城市名称和地址,然后单击按钮获取placeId。现在,我看不到基于多个参数获取位置Id的选项。如何实现这一点?接受查询字符串。一种可能的解决方案是,允许用户在不同的文本字段中输入地名、城市和地址,但在发送ajax请求之前,将它们连接到一个查询字符串中 您的表单如下所示: <form id="

我正在使用Google Places API服务()根据位置名称获取位置id。用户键入一些位置名称和相关建议,用户可以从中选择并获取位置Id。我有一个要求,我需要有三个文本框和一个按钮。用户将输入地名、城市名称和地址,然后单击按钮获取placeId。现在,我看不到基于多个参数获取位置Id的选项。如何实现这一点?

接受查询字符串。一种可能的解决方案是,允许用户在不同的文本字段中输入地名、城市和地址,但在发送ajax请求之前,将它们连接到一个查询字符串中

您的表单如下所示:

<form id="form">
  <input type="text" name="place" value="">
  <input type="text" name="city" value="">
  <input type="text" name="address" value="">
  <input type="submit" value="Locate">
</form>
$( "#form" ).submit(function( event ) {

  // concatenate places into a single query string
  var query = $('input[name="place"]').val() + $('input[name="city"]').val() + $('input[name="address"]').val();

  // convert spaces to '+' symbol for query
  query = encodeURIComponent(query);

  // send ajax request
  $.ajax({url: "https://maps.googleapis.com/maps/api/place/textsearch/xml?query=" + query + "&key=YOUR_API_KEY", success: function(result){
        alert('success, now retrieve your id from result variable');
    }});

  //prevent the submit button from reloading the page
  event.preventDefault();
});
接受查询字符串。一种可能的解决方案是,允许用户在不同的文本字段中输入地名、城市和地址,但在发送ajax请求之前,将它们连接到一个查询字符串中

您的表单如下所示:

<form id="form">
  <input type="text" name="place" value="">
  <input type="text" name="city" value="">
  <input type="text" name="address" value="">
  <input type="submit" value="Locate">
</form>
$( "#form" ).submit(function( event ) {

  // concatenate places into a single query string
  var query = $('input[name="place"]').val() + $('input[name="city"]').val() + $('input[name="address"]').val();

  // convert spaces to '+' symbol for query
  query = encodeURIComponent(query);

  // send ajax request
  $.ajax({url: "https://maps.googleapis.com/maps/api/place/textsearch/xml?query=" + query + "&key=YOUR_API_KEY", success: function(result){
        alert('success, now retrieve your id from result variable');
    }});

  //prevent the submit button from reloading the page
  event.preventDefault();
});