google map markers from database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • George Thompson
    New Member
    • Dec 2011
    • 33

    #1

    google map markers from database

    ok so this was a strange one... i have code written that loops through my database and pulls out markers and siplays them on my google maps... but here is my problem, last week my web hose was networksolution s, and i was on a shared web server... the code worked and ran fine. this week i changed over to a dedicated server, and trying to run the same code, when i add a point on the map and refresh, the map goes blank... and the whole map disapears. any ideas? both servers were running about the same versions of php and mysql, cant quite get my head around this one...

    Code:
    <script src="js/jquery-1.4.2.js" type="text/javascript"></script>
    <script src="js/jquery-ui-1.8.16.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3&sensor=false"></script>
    <script type="text/javascript">
    var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
    new google.maps.Size(32, 32), new google.maps.Point(0, 0),
    new google.maps.Point(16, 32));
    var center = null;
    var map = null;
    var currentPopup;
    var bounds = new google.maps.LatLngBounds();
    function addMarker(lat, lng, info) {
    var pt = new google.maps.LatLng(lat, lng);
    bounds.extend(pt);
    var marker = new google.maps.Marker({
    position: pt,
    icon: icon,
    map: map
    });
    var popup = new google.maps.InfoWindow({
    content: info,
    maxWidth: 300
    });
    google.maps.event.addListener(marker, "click", function() {
    if (currentPopup != null) {
    currentPopup.close();
    currentPopup = null;
    }
    popup.open(map, marker);
    currentPopup = popup;
    });
    google.maps.event.addListener(popup, "closeclick", function() {
    map.panTo(center);
    currentPopup = null;
    });
    }
    function initMap() {
    map = new google.maps.Map(document.getElementById("map"), {
    center: new google.maps.LatLng(36.879, -96.537),
    zoom: 3,
    mapTypeId: google.maps.MapTypeId.HYBRID,
    mapTypeControl: true,
    mapTypeControlOptions: {
    style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
    },
    navigationControl: true,
    navigationControlOptions: {
    style: google.maps.NavigationControlStyle.SMALL
    }
    });
    <?
    
    $mapquery = mysql_query("SELECT * FROM worldmap WHERE memid='$id' ");
    while($Mrow = mysql_fetch_array($mapquery)){
    $name = $Mrow['name'];
    $lat = $Mrow['latitude'];
    $lon = $Mrow['longitude'];
    $desc = $Mrow['description'];
    
    echo ("addMarker($lat, $lon,'<b>$name</b><br/>$desc');\n");
    }
    
    ?>
    center = bounds.getCenter();
    map.fitBounds(bounds);
    }
    </script>
    
    </head>
    
    <body onLoad="initMap()">
    <div id="map"></div>
    <?
    
    $mapquery = mysql_query("SELECT * FROM worldmap WHERE memid='$id' ");
    while($Mrow = mysql_fetch_array($mapquery)){
    $name = $Mrow['name'];
    $lat = $Mrow['latitude'];
    $lon = $Mrow['longitude'];
    $desc = $Mrow['description'];
    
    echo ("addMarker($lat, $lon,'<b>$name</b><br/>$desc');\n");
    }
    
    ?>
    </body>
    any help will be appreciated... if i run just the php query all by itself it runs fine and displays text... but when i run it in the map script the map just goes blank and disapears... thanks again
    gt
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Check the error console. Do you see any error messages?

    Comment

    • George Thompson
      New Member
      • Dec 2011
      • 33

      #3
      no there were no aparent errors... but i fixed it, i just pretty much re wrote the whole code in a different fashion.... thanks gt

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        If you're still following this thread, please post your solution in case it could be of help to others.

        Comment

        • George Thompson
          New Member
          • Dec 2011
          • 33

          #5
          the following was my solution.. thank you gt

          Code:
          <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
          <script type="text/javascript">
          	var geocoder;
          	var map;
          function initialize(){
          	var latlng = new google.maps.LatLng(36.879,-96.537);
          	var myOptions = {
          		zoom: 3,
          		center: latlng,
          		mapTypeId: google.maps.MapTypeId.HYBRID,
          		scaleControl: true,
          		navigationControl: true,
          		navigationControlOptions:{
          			style: google.maps.NavigationControlStyle.SMALL
          		},
          		mapTypeControl: true,
          		mapTypeControlOptions:{
          			style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
          		}
          	};
          		map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
          		google.maps.event.addListener(map, 'click', function(event){
          			placeMarker(event.latLng);
          			findAddress(event.latLng);
          		});
          	}
          	function findAddress(loc){
          		geocoder = new google.maps.Geocoder(); 
          		if (geocoder){
          			geocoder.geocode({'latLng': loc}, function(results, status){
          				if (status == google.maps.GeocoderStatus.OK){
          					if (results[0]){
          						address = results[0].formatted_address;
          						document.getElementById('lat').value = loc.lat();
          						document.getElementById('long').value = loc.lng();
          					}
          				}
          			});
          		}
          	}
          	var marker;
          	function placeMarker(location){
            		if(marker){
              		marker.setPosition(location);
            		}else{
              		marker = new google.maps.Marker({
                			position: location,
                			map: map
              		});
            		}
          	}
          	google.maps.event.addListener(map, 'click', function(event){
            		placeMarker(event.latLng);
          	});
          </script>

          Comment

          Working...