[英]Is it possible to place Bing/Google Maps autocomplete postal address textbox in desktop windows form app using C#?
I'm a noob at C#, this is my first programming language and I am currently working my way through the book C# in a Nutshell. 我是C#的新手,这是我的第一门编程语言,目前我正在《 Nutshell》这本书的写作中。 I have started a project to automate a lot of what I do at work all day.
我已经启动了一个项目,以使我整天的工作自动化。
If it is possible can anyone recommend a good place to start researching how to do this specifically? 如果有可能的话,有人可以推荐一个合适的地方来开始专门研究如何做到这一点吗? The only resource that I can find is:
我可以找到的唯一资源是:
Google maps autocomplete textbox in c# Google在C#中映射自动完成文本框
But he says in the end he could never get it to work. 但他说,最终他永远无法使它运转。 It gives me an idea about how to go about it but I don't know what he was doing wrong.
它给了我一个解决方法的想法,但我不知道他在做什么错。
I want to implement an order placing system and the first thing the user will need to do is enter customer name and address. 我要实现一个下订单系统,用户要做的第一件事就是输入客户名称和地址。
The end game is getting the address and comparing it to a database of stored addresses, if the post/zip code matches then load up the account and if it doesn't then create a new account using the address details. 最终游戏将获取地址并将其与存储的地址数据库进行比较,如果邮政编码匹配,则加载该帐户,如果不匹配,则使用地址详细信息创建一个新帐户。
Being able to use a Microsoft or Google api would prevent me from having to host a database with every UK address in it. 能够使用Microsoft或Google api将使我不必托管包含每个英国地址的数据库。
EDIT: https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform 编辑: https : //developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform
As per Google, below is the JavaScript code for this functionality but in a web page. 按照Google的规定,以下是此功能的JavaScript代码,但在网页中。 As you can see the comments state that the JS library Places is required.
如您所见,注释指出JS库Places是必需的。 Does this mean I can't just work on the conversion and that some functionality will be missing.
这是否意味着我不能只从事转换工作,某些功能将丢失。 This is all embedded within HTML which I have not included:
这些都是嵌入在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 only provides auto suggest/complete through their web control currently. Bing Maps当前仅通过其Web控件提供自动建议/完成。 You can host this inside of a web browser control in your app but that will be messy and likely won't work well with your layout.
您可以将其托管在应用程序中的网络浏览器控件中,但这会很杂乱,可能无法很好地配合您的布局。
Take a look at Azure Location Based Serv- ices. 看一下基于Azure位置的服务。 They have several REST services which can be used for auto suggest/complete for addresses/places, points of interest and more.
他们有几个REST服务,可用于自动建议/完成地址/地点,景点等。 Simply set the
typeahead
URL parameter to true to put the service into predictive mode. 只需将
typeahead
URL参数设置为true,即可将服务置于预测模式。 Here are some useful resources: 以下是一些有用的资源:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.