Reputation: 751
I have an ASP.NET MVC application which is pretty simple so far, but I want to add a driving directions page to the clients location. I see plenty of examples using the traditional code behind model but none with ASP.NET MVC. The application uses master pages and content pages.
I'm pretty new to ASP.NET MVC, so bear with me. Any examples of doing this would be much appreciated.
PS: I'm not totally against integrating a standard code behind type page in the application if needs be.
Upvotes: 6
Views: 14595
Reputation: 6981
Take a look at this project (Google map control for ASP.NET MVC). Maybe it can help you to create some helper that wrap the functionality you want.
Upvotes: 0
Reputation: 37875
I've used the Google Maps API for exactly the same need as you (driving directions, as well as calculations for fuel economy, etc.). What I'll normally do is pull what I need from the database in the back-end and structure it into a list of some type which I can then fill in a hidden control or literal. Then on the front end I'll have the JavaScript code pick it apart and send off the requests to the maps API.
I don't know how much different it could potentially be with the ASP.NET MVC framework, but I would imagine not too much.
Upvotes: 2
Reputation: 3492
I think tvanfosson is correct; you should look at JavaScript examples. The fact that you're using ASP.NET MVC won't really affect your Google Maps code. Write the Google maps code in one of your view content pages just as you would in a standard ASP.NET application, or even just a plain HTML + JavaScript application. The only difference is that you will want to dynamically add JavaScript variables or parameters so your Google Maps code can use it.
I think you should not put any of your logic in a code-behind file. It will keep your project cleaner to keep logic in the controller, and using a code-behind won't really help you here. Instead have your controller perform the logic and hand the results to the view in the ViewData.
Upvotes: 7
Reputation: 4250
There is a blog post about using Google Maps with ASP.NET MVC here: Using Google Maps with the MVC Framework
edit: The solution doesn't work for me as is, probably due to being built with an older version of the MVC framework. In order to fix it I had to replace the following line in the project's Web.Config:
<add namespace="Microsoft.Web.Mvc"/>
with the following line:
<add namespace="System.Web.Mvc.Html" />
Upvotes: 2
Reputation: 532445
I'd probably look for examples that interact through Javascript rather than via .NET interface. Check out the Google Maps API documentation at http://code.google.com/apis/maps/documentation/index.html, examples at http://code.google.com/apis/maps/documentation/examples/index.html.
Upvotes: 4