简体   繁体   中英

Perform a Google/Bing Maps search from a utr

I'm working on project that simulates (for lack of better word) a GPS. The user is able to select a State, City and address eg 000 someadress.dr and I have it set up so that when the submit button is clicked all of these components are combined into a single string. I'm wondering if its possible to perform a map search on either platform through the address bar, if it is could possibly do something like this:

private void btnSubmitAddress_Click(object sender, EventArgs e) {

    string stateSelected = this.cbState.Text; // Stores the selected State
    string citySelected = this.cbCity.Text; // Stores the selected City
    string addressSelected = this.cbPreDefAddress.Text; // Store the selected address

    string result = addressSelected + " " + citySelected + " " + stateSelected; // Creates a single address string.

    wbSatNavBrowser.Navigate("https://www.bing.com/maps/search?" + result);
}

The Bing Maps website is a consumer product and shouldn't be loaded inside of business applications. Instead, consider using the Bing Maps developer API's. The Bing Maps WPF control works inside of WinForms, here is a blog post on this: https://rbrundritt.wordpress.com/2012/01/05/using-bing-maps-in-winforms/

You can geocode locations using the REST services. Here is a great .NET library for using these services: https://github.com/Microsoft/BingMapsRESTToolkit

If you want the most mapping features, you can also host the Bing Maps web control inside of a web browser control. Here is a code sample: https://code.msdn.microsoft.com/Using-the-Bing-Maps-V8-Web-07e21f3a?redir=0

The docs show some examples of how to pass parameters.

This example sets the centerpoint of the map.

http://bing.com/maps/default.aspx?cp=47.677797~-122.122013

To open Bing Maps to a specific address:

http://bing.com/maps/default.aspx?rtp=adr.One%20Microsoft%20Way,%20Redmond,%20WA%2098052~pos.45.23423_-122.1232_MyPlace&rtop=0~1~0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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