繁体   English   中英

是否可以使用C#将Bing / Google地图自动填充邮政地址文本框放置在桌面Windows窗体应用程序中?

[英]Is it possible to place Bing/Google Maps autocomplete postal address textbox in desktop windows form app using C#?

我是C#的新手,这是我的第一门编程语言,目前我正在《 Nutshell》这本书的写作中。 我已经启动了一个项目,以使我整天的工作自动化。

如果有可能的话,有人可以推荐一个合适的地方来开始专门研究如何做到这一点吗? 我可以找到的唯一资源是:

Google在C#中映射自动完成文本框

但他说,最终他永远无法使它运转。 它给了我一个解决方法的想法,但我不知道他在做什么错。

我要实现一个下订单系统,用户要做的第一件事就是输入客户名称和地址。

最终游戏将获取地址并将其与存储的地址数据库进行比较,如果邮政编码匹配,则加载该帐户,如果不匹配,则使用地址详细信息创建一个新帐户。

能够使用Microsoft或Google api将使我不必托管包含每个英国地址的数据库。

编辑: https : //developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform

按照Google的规定,以下是此功能的JavaScript代码,但在网页中。 如您所见,注释指出JS库Places是必需的。 这是否意味着我不能只从事转换工作,某些功能将丢失。 这些都是嵌入在HTML中的,我还没有包括:

// This example displays an address form, using the autocomplete feature
// of the Google Places API to help users fill in the information.

// This example requires the Places library. Include the libraries=places
// parameter when you first load the API. For example:
// <script src="https://maps.googleapis.com/maps/api/js?  key=YOUR_API_KEY&libraries=places">

var placeSearch, autocomplete;
var componentForm = {
  street_number: 'short_name',
  route: 'long_name',
  locality: 'long_name',
  administrative_area_level_1: 'short_name',
  country: 'long_name',
  postal_code: 'short_name'
};

function initAutocomplete() {
  // Create the autocomplete object, restricting the search to geographical
  // location types.
  autocomplete = new google.maps.places.Autocomplete(
      /** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
      {types: ['geocode']});

  // When the user selects an address from the dropdown, populate the address
  // fields in the form.
  autocomplete.addListener('place_changed', fillInAddress);
}

function fillInAddress() {
  // Get the place details from the autocomplete object.
  var place = autocomplete.getPlace();

  for (var component in componentForm) {
    document.getElementById(component).value = '';
    document.getElementById(component).disabled = false;
  }

  // Get each component of the address from the place details
  // and fill the corresponding field on the form.
  for (var i = 0; i < place.address_components.length; i++) {
    var addressType = place.address_components[i].types[0];
    if (componentForm[addressType]) {
      var val = place.address_components[i][componentForm[addressType]];
      document.getElementById(addressType).value = val;
    }
  }
}

// Bias the autocomplete object to the user's geographical location,
// as supplied by the browser's 'navigator.geolocation' object.
function geolocate() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      var geolocation = {
        lat: position.coords.latitude,
        lng: position.coords.longitude
      };
      var circle = new google.maps.Circle({
        center: geolocation,
        radius: position.coords.accuracy
      });
      autocomplete.setBounds(circle.getBounds());
    });
  }
}

Bing Maps当前仅通过其Web控件提供自动建议/完成。 您可以将其托管在应用程序中的网络浏览器控件中,但这会很杂乱,可能无法很好地配合您的布局。

看一下基于Azure位置的服务。 他们有几个REST服务,可用于自动建议/完成地址/地点,景点等。 只需将typeahead URL参数设置为true,即可将服务置于预测模式。 以下是一些有用的资源:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM