<newbie> Using Google maps on ASP.NET 2.0 pages, how??

J

Jeff

Hey

I'm wondering how to use Google Maps on a ASP.NET 2.0 page?

I've read a few tutorials on this subject and I'm a bit confused. Some so it
is straight forward. Just put the google map code into the .aspx page and
run it - I have never been able to run it if I put some google map code
(javascript) directly into the .aspx file...

Some other articles I've read suggest creating a custom ASP.NET 2.0 server
control which works as a ASP.NET Google Map - And because it is a server
control, data can be bound to it.

For example this article http://dotnet.sys-con.com/read/171162.htm says
it'll describe how to create a Google Map control. I've read it I still
don't understand how to do it. The article shows lot of fancy screenshots of
the control, but it don't describe how to make the control... - or is it
something I've completely missunderstood...

Any suggestions??

Jeff
 
M

Michael Nemtsev

Hello jeff,

Discussed recently http://groups.google.com/group/micr...read/thread/99e9938aef5787d2/36c16c5171cdf0fe

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

j> Hey
j>
j> I'm wondering how to use Google Maps on a ASP.NET 2.0 page?
j>
j> I've read a few tutorials on this subject and I'm a bit confused.
j> Some so it is straight forward. Just put the google map code into the
j> .aspx page and run it - I have never been able to run it if I put
j> some google map code (javascript) directly into the .aspx file...
j>
j> Some other articles I've read suggest creating a custom ASP.NET 2.0
j> server control which works as a ASP.NET Google Map - And because it
j> is a server control, data can be bound to it.
j>
j> For example this article http://dotnet.sys-con.com/read/171162.htm
j> says it'll describe how to create a Google Map control. I've read it
j> I still don't understand how to do it. The article shows lot of fancy
j> screenshots of the control, but it don't describe how to make the
j> control... - or is it something I've completely missunderstood...
j>
j> Any suggestions??
j>
j> Jeff
j>
 
G

Guest

Just put the google map code into the .aspx page and
run it - I have never been able to run it if I put some google map code
(javascript) directly into the .aspx file...

Yes, you just need to put a google maps code into an .aspx page. If it
doesn't work, give us an example of your code.

Note, you would need to have an API key.
http://www.google.com/apis/maps/signup.html

The interface to Google Maps is based on JavaScript, it means you have
to include a JavaScript from maps.google.com. You can build a control,
whatever, however it is not required for the solution to work.
 
J

Jeff

Thanks for replying to my post, I really appreaciate it :)

Here is the markup of a simple .aspx page I created with google map... I
doesn't work!... It compiles, but no map are displayed. .. In the status
line of the browser, the text "error on page" appear for a few seconds
before it changes to "done"

Here is the source code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body onload="load()" onunload="GUnload()" >
<form id="form1" runat="server">
<div>
<script
src="http://maps.google.com/maps?file=ap...alGLpuFeoa9XJoGVRRnp2bV6uZCXNFMgTSq91QjaeZ_5w"
type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
}
}
//]]>
</script>

</div>
</form>
</body>
</html>

any suggestions?

Jeff
 
G

Guest

Thanks for replying to my post, I really appreaciate it :)

Here is the markup of a simple .aspx page I created with google map... I
doesn't work!... It compiles, but no map are displayed. .. In the status
line of the browser, the text "error on page" appear for a few seconds
before it changes to "done"


Hi Jeff,

regarding your code

1) It compiles/doesn't compiles - since you don't have any code-behind
it makes no sense
2) document.getElementById("map")) refers to an object named "map"

add a DIV with id="map" to your code,

for example

<div id="map" style="width: 400px; height: 400px"></div>
</form>
</body>
</html>

It will show you a map 400x400 using Google Maps API
 
J

Jeff

The markup below works. I'm wondering if it is okay to use a google map like
I do below are should I make some changes to my code? for example put some
of the google map code to the code behind file, if that is possible?? and
lets say I have a database containing locations... how do I add those to the
map - Could it be done by having a method in the code behind file which
retrieve the locations from database and put them into the map?? and what
about when clicking inside the map, then I want that location clicked to be
stored in the database, how do I go about to that in asp.net 2.0??

I've created a simple test page based on php which are using ajax to save
data to the database etc.. but now I wants to learn how to the same using
ASP.NET 2.0

Any suggestions??


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body onload="load()" onunload="GUnload()" >
<form id="form1" runat="server">
<div>
<script
src="http://maps.google.com/maps?file=ap...alGLpuFeoa9XJoGVRRnp2bV6uZCXNFMgTSq91QjaeZ_5w"
type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
}
}
//]]>
</script>
<div id="map" style="width: 500px; height: 300px"></div>
</div>
</form>
</body>
</html>
 
G

Guest

for example put some
of the google map code to the code behind file, if that is possible??

Once again: the Google Maps API is a javascript based. You can put a
google map code to the code behind file, but it should create the same
javascript code. That is

Response.Write(@"<script type="text/javascript">
//<![CDATA[....");

I don't know if it makes any sense.

lets say I have a database containing locations... how do I add those to the
map - Could it be done by having a method in the code behind file which
retrieve the locations from database and put them into the map??

Acc. to the Google Maps API tutorial:
http://www.google.com/apis/maps/documentation/index.html

Using XML and Asynchronous HTTP with Maps

You can make a web form, a web service, etc. to return a XML that
contains a list of coordinates from database.

and what
about when clicking inside the map, then I want that location clicked to be
stored in the database, how do I go about to that in asp.net 2.0??

It's all about Javascript and Google Maps API. There is nothing
related to ASP.net 2.0.

Acc. to the Google Maps API tutorial:
http://www.google.com/apis/maps/documentation/index.html

Click Handling

When a user clicks the map, API registers a "click" event. Using that
event you can create a javascript call of a server side function, e.g.
"savelocation.aspx?lat=xxxx&lng=yyyyy" where lat and lng came from
that "click" event.

Hope it helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top