SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Google Maps

  1. #1
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Google Maps

    I am looking to have a google map on one of my dynamically created pages to show the location of whatever the page is about at that time. I can find the spot on the google map itself but how do I use the map to find the coordinates for which I can place a little red circle. and what is the easiest way of placing a small image on a google map at a specific spot?

    Update: I ahve managed to figure out hwo to get the latitude and longitude of a specific map on a google map but I ahve a few questions:

    1. How do I set the map to display in satelite mode by default?
    2. If I ahve an image of a red circle, how do I set the image to be shown at the location of the map?
    Last edited by rctneil; May 2, 2008 at 02:01.

  2. #2
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,
    Thought I would just post my current google maps code:

    Code HTML4Strict:
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAhsFNoGL2T4i9eb5AdjtFZBSTuhz8G4ESXdp0n8vcpYzjn-vcBhQWX9-zRCu3NDoomQN0s9qTzl3Ahw"
          type="text/javascript"></script>
        <script type="text/javascript">
        //<![CDATA[
        function load() {
          if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map"));
            	map.enableContinuousZoom();
    			map.enableDoubleClickZoom();
    			//map.addControl(new GMapTypeControl());
    			//map.addControl(new GOverviewMapControl());
    			//map.addControl(new GScaleControl());
    			//map.addControl(new GLargeMapControl());
    			map.setMapType(G_SATELLITE_MAP);
    			//map.setCenter(new GLatLng(52.98696, -1.88677), 8);
    			map.setCenter(new GLatLng(52.98868924123148, -1.8904691934585571), 16);
          }
        }
        //]]>
        </script>
    Thats what I ahve before but the line starting with map.setMapType just makes the map turn grey and not do anything and maes the browser status area say "Erro on Page"

    Can anyone help with this?

  3. #3
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Also, I have tried to set the map to get the latitude and logitude of a specific item from a database. Have I correctly included the PHP in the snippet of code below:

    PHP Code:
    map.setCenter(new GLatLng(<?php echo $getridedata['ride_latlong']; ?>), 16);

  4. #4
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm still having trouble with getting this to work. Below is the full code of the page with the map on. Could someone try it out to try to figure out whats wrong with it. The map just goes grey:

    Code HTML4Strict:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <title>Google Maps JavaScript API Example</title>
        <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAhsFNoGL2T4i9eb5AdjtFZBSTuhz8G4ESXdp0n8vcpYzjn-vcBhQWX9-zRCu3NDoomQN0s9qTzl3Ahw"
          type="text/javascript"></script>
        <script type="text/javascript">
        //<![CDATA[
        function load() {
          if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map"));
            	map.enableContinuousZoom();
    			map.enableDoubleClickZoom();
     
    			map.addControl(new GMapTypeControl());
    			var point = new GLatLng(52.98868924123148, -1.8904691934585571);
    			map.addOverlay(new GMarker(point));
    			//map.addControl(new GOverviewMapControl());
    			map.addControl(new GScaleControl());
    			map.addControl(new GLargeMapControl());
    			map.setMapType(G_SATELLITE_MAP);
    			//map.setCenter(new GLatLng(52.98696, -1.88677), 8); //ST10 4DB Overview
    			map.setCenter(new GLatLng(52.98868924123148, -1.8904691934585571), 16); //Battle Galleons Zoomed in
    			//map.setCenter(new GLatLng(<?php echo $getridedata['ride_latlong']; ?>), 16);
          }
        }
        //]]>
        </script>
    <style type="text/css">
    <!--
    body {
    	margin-left: 0px;
    	margin-top: 0px;
    	margin-right: 0px;
    	margin-bottom: 0px;
    }
    -->
    </style>
      </head>
      <body onload="load()" onunload="GUnload()">
        <div id="map" style="width: 500px; height: 300px"></div>
      </body>
    </html>



    Note: I have tried deleting my other posts above to just leave this one but it won;t let me so forgive me for that!

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Dont take offence, rctniel but I don't know why you are fiddling around with this PHP/JS stuff if you don't know what you are doing.

    The PHP examples on the google maps site are simply outstanding.

    I just copied and pasted them locally and they just work - its real quality stuff they put into those samples.

    If you are stuck then I would say go and register on the google maps group like the documentation tells you to do - because if you cant figure this stuff out you are going to have a really bad time with gmaps.

    ps I don't think this is the cause of you hardships, but why do you feel your coordinates have to 14 decimal places when the examples show only 5?

    pps If you wonder what
    browser status area say "Erro on Page"
    means then you should download the firefox firebug and DomInspector extensions - look inside your Tools / Error Console

  6. #6
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right,
    Why can;t someone have a go at JS even though don't know what they are doing?

    and just to let you know, I do know quite a bit of PHP but I am still getting used to it. The PHP question I asked wasn't about PHP really but how to use PHP inside JS to pass it a value. - thats what I need to know.

    Can you pass me a link to the PHP examples if they are really good and of course I shall take a look at them.

    The coordinates are ones that I got from a site that I found on the map the thing I wanted the coordinates for, centered the location on that area and used some javascript in the addressbar to have a popup show up which gave me the coordinates. It's not really a big deal that they are stupidly long number of digits does it?

    Thanks,
    Neil

  7. #7
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Neil, I don't know why you've posted this thread in the XHTML/HTML forum. What is it you need help with? The PHP or the JavaScript? Let me know, and I'll move the thread to the appropriate forum.
    Birnam wood is come to Dunsinane

  8. #8
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the javascript please


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •