I have a sample based on the link https://learn.microsoft.com/en-us/bingmaps/v8-web-control/map-control-concepts/search-module-examples/basic-geocode-example and set some custom options.
# Address
1.DE Deutschland
2.Siemensstraße DE Deutschland
3.Siemensstraße DE 73479 Deutschland - Ellwangen
4.Siemensstraße DE 73635 Deutschland - Rudersberg
5.Siemensstraße DE 71254 Deutschland - Ditzingen
# Code Snippet
var searchRequest = {
...,
count: 25,
callback: function(r){
map.setView({ bounds: r.results[0].bestView });
},
...
};
# Search Results
- Every first search for above address yields the desired results, below are search text & results.
Siemensstraße DE 73479 Deutschland
# Siemensstraße, **73479** Ellwangen, Germany
Siemensstraße DE 73635 Deutschland
# Siemensstraße, **73635** Rudersberg, Germany
# Siemensstraße, **73635** Oberndorf, Germany
Siemensstraße DE 71254 Deutschland
# Siemensstraße, **71254** Ditzingen, Germany
- But if following below search orders without reload the page after per search, the result was not as expected.
DE Deutschland -> Siemensstraße DE Deutschland -> Siemensstraße DE 73635 Deutschland
# Siemensstraße, **10553** Berlin, Germany
# Siemensstraße, **10551** Berlin, Germany
It seems calls map.setView function will change the viewport and affects next search's parameter "usermapview", for the same query text, different "usermapview" might lead to different results.
For the second case, only 2 results were returned, It doesn't even include the desired results "Siemensstraße, 73635 Rudersberg, Germany" and "Siemensstraße, 73635 Oberndorf, Germany“
# Request URLs ( second case)
# https://dev.ditu.live.com/REST/v1/Locations/?q=DE%20Deutschland&o=json&jsonp=Microsoft.Maps.NetworkCallbacks.f629a2&key=AmbspgUflTI-maTYRpiwUeF5mA6kXUUfmjykps33RhHYZGUSyE6Up_AySUpHT5AE&maxResults=5&userMapView=23.123920800261175,113.25951504707336,23.134280598833783,113.26927828788757&inclnb=0&incl=&ur=cn&c=en-US
# https://dev.ditu.live.com/REST/v1/Locations/?q=Siemensstra%C3%9Fe%20DE%20Deutschland&o=json&jsonp=Microsoft.Maps.NetworkCallbacks.f6a5e3&key=AmbspgUflTI-maTYRpiwUeF5mA6kXUUfmjykps33RhHYZGUSyE6Up_AySUpHT5AE&maxResults=5&userMapView=43.55492527250473,0.45519447326659446,57.98947250054124,20.450311660766594&inclnb=0&incl=&ur=cn&c=en-US
# https://dev.ditu.live.com/REST/v1/Locations/?q=Siemensstra%C3%9Fe%20DE%2073635%20Deutschland&o=json&jsonp=Microsoft.Maps.NetworkCallbacks.f704fc&key=AmbspgUflTI-maTYRpiwUeF5mA6kXUUfmjykps33RhHYZGUSyE6Up_AySUpHT5AE&maxResults=5&userMapView=52.52608813430596,13.31912459872878,52.53979358856163,13.338651080357199&inclnb=0&incl=&ur=cn&c=en-US
Our scenarios is when user enter text in fields like "street", "zipcode" in a form, then make a geocode call to request the matched locations, the request orders may be like below:
- enter "Siemensstraße” in street field -> sending a geocode request
- enter "73635“ in zipcode filed -> sending a geocode request
- every geocode response will be use to fill the other fields in form such as "longitude", "latitude" ...
Is there any way to always get desired locations?