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

Discussion in 'ASP .Net' started by Jeff, Apr 29, 2007.

  1. Jeff

    Jeff Guest

    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
    Jeff, Apr 29, 2007
    #1
    1. Advertising

  2. 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>
    Michael Nemtsev, Apr 30, 2007
    #2
    1. Advertising

  3. On Apr 29, 10:52 pm, "Jeff" <> wrote:
    > 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.
    Alexey Smirnov, Apr 30, 2007
    #3
  4. Jeff

    Jeff 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"

    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=api&amp;v=2&amp;key=ABQIAAAAtil_7JSZXkq9VTwQkvppgRTj87-E8mkBwalGLpuFeoa9XJoGVRRnp2bV6uZCXNFMgTSq91QjaeZ_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
    Jeff, Apr 30, 2007
    #4
  5. On Apr 30, 9:03 pm, "Jeff" <> wrote:
    > 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
    Alexey Smirnov, Apr 30, 2007
    #5
  6. Jeff

    Jeff Guest

    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=api&amp;v=2&amp;key=ABQIAAAAtil_7JSZXkq9VTwQkvppgRTj87-E8mkBwalGLpuFeoa9XJoGVRRnp2bV6uZCXNFMgTSq91QjaeZ_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>
    Jeff, May 1, 2007
    #6
  7. On May 1, 10:46 pm, "Jeff" <> wrote:
    > 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
    Alexey Smirnov, May 1, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    2,014
    Jeffrey Schwab
    Nov 28, 2005
  2. Sam Carleton
    Replies:
    6
    Views:
    853
    =?Utf-8?B?RGlhbmUgRHJvdWJheQ==?=
    Jul 12, 2006
  3. MeerkatInFrance

    Google Maps & Master Pages

    MeerkatInFrance, Aug 11, 2006, in forum: ASP .Net
    Replies:
    17
    Views:
    2,288
    FightBack
    Jan 11, 2007
  4. xml .NET group

    Google Maps using ASP.NET

    xml .NET group, Apr 24, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    387
    Lenny
    Apr 25, 2007
  5. Replies:
    0
    Views:
    478
Loading...

Share This Page