Using Google Maps API in .NET 3.5 ASP.NET MVC application
Asked Answered
L

5

6

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.

Latvia answered 28/2, 2009 at 16:52 Comment(0)
I
7

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.

Instar answered 28/2, 2009 at 18:39 Comment(1)
Thanks - played with jquery to get it to work within my content page and it works.Latvia
C
4

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.

Clean answered 28/2, 2009 at 18:1 Comment(0)
R
2

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.

River answered 28/2, 2009 at 18:28 Comment(0)
D
2

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" />
Dorren answered 11/4, 2009 at 15:12 Comment(0)
S
0

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.

Streusel answered 12/8, 2011 at 10:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.