Microsoft Developer Network >
Forums Home
>
Windows Live Developer Forums Forums
>
Bing Maps: Map Control Development
>
Getting Started with Bing Maps API
Getting Started with Bing Maps API
- Okay, this is a long, drawn-out situation, and may not be unique, but I don't see any easy access to the answers I need, so I'm posting the questions.
1) I'm testing map functionality with Bing Maps at present. Ultimately, I'd like to build a user control that will accept one or more locations (which may be lat-long combos or city names) and render the map with those locations and, if more than one, the routes.
2) However, in the beginning, I'd like to have a better understanding of how the map API works. For now, I'm just trying to send first one, then two lat-long pairs into the javascript example I found at MSDN, to no avail. I have tried doing javascript injections using both RegisterStartupScript() and RegisterClientScriptBlock(), but in neither case does this work, because the GetMap() function event is triggered at initial render, not on submit, and in either case, the javascript injection puts the code into the body of the HTML, not the header. And I cannot allow the lat-long pairs to be sent simply through GET or POST because they will be accessible and unsafe. I want to know how to do this in the context of ASP.NET.
3) I will not be able to use either AJAX or Silverlight in production for the foreseeable future; therefore, I'd like to figure out how to best utilize Bing Maps and perhaps create my own custom control that will avoid the use of either of these technologies.
4) I'm trying to use this with a prototype web portal that I'm building and designing, so I need to be able to use the Bing Maps within that context, which still must meet my client's production requirements (thus, no AJAX or Silverlight).
5) Putting javascript into web user controls doesn't seem to work properly.
Is there any way to create a wrapper for the Bing Maps API and expose method calls in code? That would be the most effective solution.
Thanks!
All Replies
- 1. When you say: "Is there any way to create a wrapper for the Bing Maps API and expose method calls in code?" Please clarify? Do you mean server-side or client-side code? If you wish to initialize the map using arguments provided server-side .NET code, look at the Map server control (http://www.microsoft.com/downloads/details.aspx?FamilyID=f438b207-96af-497c-94db-152d48344af5&DisplayLang=en) or at the concept of creating an extender which allows you to initialize the map using server-side code ( use the links here to view all 3 parts of the tutorial:
http://dotnetslackers.com/colum/ajax/ASPNETAJAXMeetsVirtualEarthPartThree.aspx). While the second method uses the .NET AJAX framework, you do not necessarily need to use AJAX method calls. I can explain further about the extender if that is something you are interested in.
2. It would help to understand the layout of the page. Are you using an update panel? Do you have the map on its own page? Do you have a form and the submit button on one side of the page and the map on the other side? I guess my question is whether you want to do something on a postback or purely use the javascript API? Perhaps sample code will illustrate what you are trying to do.
3) I will not be able to use either AJAX or Silverlight in production for the foreseeable future; therefore, I'd like to figure out how to best utilize Bing Maps and perhaps create my own custom control that will avoid the use of either of these technologies.
The client-side Bing Map controls need either AJAX or Silverlight. If you don't want to use either of these then the only option you have is to use the Bing Web Services.
These are a set of webservices that you can access via server-side SOAP methods - there's a different service to request map imagery, to perform searchs, to perform geocoding, and to obtain routing information.
The method reference is here:
http://msdn.microsoft.com/en-us/library/cc980922.aspx
The best place to look for sample code is on Chris Pendleton's blog, such as this article:
http://www.bing.com/community/blogs/maps/archive/2008/11/05/pushpins-and-virtual-earth-web-service-maps.aspx
Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290- Unfortunately, the link to dotnetslackers has been removed; but that was of greatest interest, as I would prefer to use server-side code if possible. The use of javascript in the Bing Maps example led me to believe there was no server-side option, which hopefully also addresses your first point.
I am not using an UpdatePanel control on my page at present. I had the sample code, which renders a map of LA, working in a basic code-behind .aspx page, but of course there was no code-behind needed. Essentially, I have an application that calculates locations and I wanted to render those locations both individually and as routes with multiple stops. I then used the directions of How To: Convert an ASPX page to a Web User Control (http://msdn.microsoft.com/en-us/library/2x6sx01c.aspx) to convert this basic page to a control, which didn't work, and I've been tweaking that iteratively since to see if I can figure out how to get it to work, and consequently, how to possibly accomplish my own task.
I would like to work iteratively from the test sample to a working control that accepts my inputs; but I might be missing a step or a needed direction. If I could see the tutorial you refer to, I think it would be a big help! - This looks very useful; but isn't Virtual Earth going to be deprecated? Isn't that why Bing Maps has been created? I'm still seeing Virtual Earth rather than Bing, which gives me pause. This is probably because I didn't start with VE and believed I would be working exclusively on Bing. (Chris Pendleton's blog is VE, thus the questions.)
- To clear up a couple of confusions.
1.) Bing = the new name for Virtual Earth. No different functionality, just a rebranding. In any cases where you see "Virtual Earth", you can quite safely replace it with "Bing". The name "Virtual Earth" may be deprecated, but the technology is not.
2.) The .NET control mentioned in Sasha's post (http://www.microsoft.com/downloads/details.aspx?FamilyID=f438b207-96af-497c-94db-152d48344af5&DisplayLang=en), which I think you're using, is simply a wrapper that enables you to generate client-side Bing code using .NET languages (C# or VB.Net). Any application generated using the Windows Live Tools map control still uses AJAX on the client-side . From my understanding of your post, that is no good to you, which is why I suggested the web services.
Beginning Spatial with SQL Server http://www.apress.com/book/view/1430218290 - This sounds logical. I'll be looking into the Web Services, and crossing my fingers that I will eventually be able to utilize AJAX on my portal technology.
Thanks for the clarification on VE / Bing. I will do some looking also into older code samples on VE and see if some make sense within my portal's context. - The Map extender url does work on my machine:
http://dotnetslackers.com/columns/ajax/ASPNETAJAXMeetsVirtualEarthPartOne.aspx
http://dotnetslackers.com/columns/ajax/ASPNETAJAXMeetsVirtualEarthPartTwo.aspx
http://dotnetslackers.com/columns/ajax/ASPNETAJAXMeetsVirtualEarthPartThree.aspx
This shows you how to build an extender. An extender gives client-side functionality to a server control (in this case an asp:panel) and allows you to set parameters server-side. I do warn you that it is quite sophisticated (aka takes some work). You don't have to use AJAX to get points like the article explains, you just create a variable that you fill server-side and read client-side. You will need the ASP .NET AJAX framework, but do not need to make AJAX methods calls from client to server. The client is still going to use Javascript though; you can't get away from that. If you can't require javascript, your only options are Silverlight (which you already said you couldn't use) or the web service which will return a static image (the user can't interact with the map, but can see points).
The ASP .NET server control would be an easier option but may not give you the flexibility that you desire.
- At first glance (yes, I promise I'll get more in-depth there), they seem to be using the 6.0 version of the Live Maps control. I downloaded the 6.1 version and am testing it right now, but it seems to have trouble on my page rendering. And *gulp* I do appear to be using an UpdatePanel. Of course, this is all in testing, but if I can present this effectively, I can make a strong argument for AJAX. So the help is appreciated! Is the new Bing Maps going to have a similarly updated downloadable DLL? Or is there code anywhere showing me how to do this myself? I'm also trying to find sample code on how to render points and routes in the 6.2 control, but I'm not finding any. I could really use some direction there. Thanks!
ALSO: Any chance of finding some assistance with all of this using C# and code-behind? - If you want to render routes and route geometry from c# you have to access the VE/Bing web services. But I have a feeling this is not what your looking for. You want to access the getDirections method of the VEmap. method. This will give you the directions from point A to B and you just need to display the results both alphanumerically and as a polyline on a map. If you need the web service look a the VE routing service. If you need anything hard core check out my blog here: http://rbrundritt.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&_c=BlogPart&partqs=cat%3dVE%2520Web%2520Services
Cheers mate
Windows Live Developer MVP - http://rbrundritt.spaces.live.com - Okay, now that I've had a chance to explore this further, I can correct some misunderstandings I had previously:
1) I CAN have AJAX in my present architectural configuration; but
2) I CANNOT have Silverlight.
3) I CANNOT use the Web Services; the final solution must be hosted internally.
I have downloaded the November 2008 CTP Windows Live Tools, which includes the Virtual Earth Map Control. I'm attempting to see how best to utilize this control, but I'm not having much luck. I want to use the control within an UpdatePanel on a simple web page; the user enters an origin in one box, and a destination in another box. Some behind-the-scenes processing happens, then I have a list of lat-long pairs that I want to render as a route on a VEMap. I am working in C# in Visual Studio 2008 with code-behind pages. And apparently, Microsoft has taken down any code samples for the Map Control prior to Bing Maps, so I am having terrible luck with getting an idea how to use this control. I would appreciate some direction including sample code!

