473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 networksolutions, 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...

Expand|Select|Wrap|Line Numbers
  1. <script src="js/jquery-1.4.2.js" type="text/javascript"></script>
  2. <script src="js/jquery-ui-1.8.16.min.js" type="text/javascript"></script>
  3. <script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3&sensor=false"></script>
  4. <script type="text/javascript">
  5. var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
  6. new google.maps.Size(32, 32), new google.maps.Point(0, 0),
  7. new google.maps.Point(16, 32));
  8. var center = null;
  9. var map = null;
  10. var currentPopup;
  11. var bounds = new google.maps.LatLngBounds();
  12. function addMarker(lat, lng, info) {
  13. var pt = new google.maps.LatLng(lat, lng);
  14. bounds.extend(pt);
  15. var marker = new google.maps.Marker({
  16. position: pt,
  17. icon: icon,
  18. map: map
  19. });
  20. var popup = new google.maps.InfoWindow({
  21. content: info,
  22. maxWidth: 300
  23. });
  24. google.maps.event.addListener(marker, "click", function() {
  25. if (currentPopup != null) {
  26. currentPopup.close();
  27. currentPopup = null;
  28. }
  29. popup.open(map, marker);
  30. currentPopup = popup;
  31. });
  32. google.maps.event.addListener(popup, "closeclick", function() {
  33. map.panTo(center);
  34. currentPopup = null;
  35. });
  36. }
  37. function initMap() {
  38. map = new google.maps.Map(document.getElementById("map"), {
  39. center: new google.maps.LatLng(36.879, -96.537),
  40. zoom: 3,
  41. mapTypeId: google.maps.MapTypeId.HYBRID,
  42. mapTypeControl: true,
  43. mapTypeControlOptions: {
  44. style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
  45. },
  46. navigationControl: true,
  47. navigationControlOptions: {
  48. style: google.maps.NavigationControlStyle.SMALL
  49. }
  50. });
  51. <?
  52.  
  53. $mapquery = mysql_query("SELECT * FROM worldmap WHERE memid='$id' ");
  54. while($Mrow = mysql_fetch_array($mapquery)){
  55. $name = $Mrow['name'];
  56. $lat = $Mrow['latitude'];
  57. $lon = $Mrow['longitude'];
  58. $desc = $Mrow['description'];
  59.  
  60. echo ("addMarker($lat, $lon,'<b>$name</b><br/>$desc');\n");
  61. }
  62.  
  63. ?>
  64. center = bounds.getCenter();
  65. map.fitBounds(bounds);
  66. }
  67. </script>
  68.  
  69. </head>
  70.  
  71. <body onLoad="initMap()">
  72. <div id="map"></div>
  73. <?
  74.  
  75. $mapquery = mysql_query("SELECT * FROM worldmap WHERE memid='$id' ");
  76. while($Mrow = mysql_fetch_array($mapquery)){
  77. $name = $Mrow['name'];
  78. $lat = $Mrow['latitude'];
  79. $lon = $Mrow['longitude'];
  80. $desc = $Mrow['description'];
  81.  
  82. echo ("addMarker($lat, $lon,'<b>$name</b><br/>$desc');\n");
  83. }
  84.  
  85. ?>
  86. </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
Dec 22 '11 #1

✓ answered by George Thompson

the following was my solution.. thank you gt

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  2. <script type="text/javascript">
  3.     var geocoder;
  4.     var map;
  5. function initialize(){
  6.     var latlng = new google.maps.LatLng(36.879,-96.537);
  7.     var myOptions = {
  8.         zoom: 3,
  9.         center: latlng,
  10.         mapTypeId: google.maps.MapTypeId.HYBRID,
  11.         scaleControl: true,
  12.         navigationControl: true,
  13.         navigationControlOptions:{
  14.             style: google.maps.NavigationControlStyle.SMALL
  15.         },
  16.         mapTypeControl: true,
  17.         mapTypeControlOptions:{
  18.             style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
  19.         }
  20.     };
  21.         map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  22.         google.maps.event.addListener(map, 'click', function(event){
  23.             placeMarker(event.latLng);
  24.             findAddress(event.latLng);
  25.         });
  26.     }
  27.     function findAddress(loc){
  28.         geocoder = new google.maps.Geocoder(); 
  29.         if (geocoder){
  30.             geocoder.geocode({'latLng': loc}, function(results, status){
  31.                 if (status == google.maps.GeocoderStatus.OK){
  32.                     if (results[0]){
  33.                         address = results[0].formatted_address;
  34.                         document.getElementById('lat').value = loc.lat();
  35.                         document.getElementById('long').value = loc.lng();
  36.                     }
  37.                 }
  38.             });
  39.         }
  40.     }
  41.     var marker;
  42.     function placeMarker(location){
  43.           if(marker){
  44.             marker.setPosition(location);
  45.           }else{
  46.             marker = new google.maps.Marker({
  47.                   position: location,
  48.                   map: map
  49.             });
  50.           }
  51.     }
  52.     google.maps.event.addListener(map, 'click', function(event){
  53.           placeMarker(event.latLng);
  54.     });
  55. </script>
  56.  

4 4517
acoder
16,027 Expert Mod 8TB
Check the error console. Do you see any error messages?
Jan 2 '12 #2
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
Jan 7 '12 #3
acoder
16,027 Expert Mod 8TB
If you're still following this thread, please post your solution in case it could be of help to others.
Jan 9 '12 #4
the following was my solution.. thank you gt

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  2. <script type="text/javascript">
  3.     var geocoder;
  4.     var map;
  5. function initialize(){
  6.     var latlng = new google.maps.LatLng(36.879,-96.537);
  7.     var myOptions = {
  8.         zoom: 3,
  9.         center: latlng,
  10.         mapTypeId: google.maps.MapTypeId.HYBRID,
  11.         scaleControl: true,
  12.         navigationControl: true,
  13.         navigationControlOptions:{
  14.             style: google.maps.NavigationControlStyle.SMALL
  15.         },
  16.         mapTypeControl: true,
  17.         mapTypeControlOptions:{
  18.             style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
  19.         }
  20.     };
  21.         map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  22.         google.maps.event.addListener(map, 'click', function(event){
  23.             placeMarker(event.latLng);
  24.             findAddress(event.latLng);
  25.         });
  26.     }
  27.     function findAddress(loc){
  28.         geocoder = new google.maps.Geocoder(); 
  29.         if (geocoder){
  30.             geocoder.geocode({'latLng': loc}, function(results, status){
  31.                 if (status == google.maps.GeocoderStatus.OK){
  32.                     if (results[0]){
  33.                         address = results[0].formatted_address;
  34.                         document.getElementById('lat').value = loc.lat();
  35.                         document.getElementById('long').value = loc.lng();
  36.                     }
  37.                 }
  38.             });
  39.         }
  40.     }
  41.     var marker;
  42.     function placeMarker(location){
  43.           if(marker){
  44.             marker.setPosition(location);
  45.           }else{
  46.             marker = new google.maps.Marker({
  47.                   position: location,
  48.                   map: map
  49.             });
  50.           }
  51.     }
  52.     google.maps.event.addListener(map, 'click', function(event){
  53.           placeMarker(event.latLng);
  54.     });
  55. </script>
  56.  
Jan 10 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: jelle | last post by:
Hi, Has anyone so far been messing accessing / quering the google desktop database files? It seems it could be the best reflection of one in a couple of hundred mb, and i intent to unleash some...
1
by: AA | last post by:
hello to aal, how its mossible to someone update may database, for now we have a database and time to time, someone update a record, changing the information. what can i do to avoid this? ...
1
by: mich dobelman | last post by:
What's the common way to integrate php and google map api? I tried to create the getShop.php script which access the db and fetch the list of shops with lat and lon information in xml document....
1
by: stephy | last post by:
I want to do a searching on database some tables' content, is asp have so function or tool to do this? thx
0
by: hybrid_snyper | last post by:
Hi all, wondering if someone can help me. im working on some tutorials for using googlemaps. Currently im working on using sql databases and php to store and retreive markers. Im very impressed...
3
by: Lemon Tree | last post by:
Hi everybody. I am new to Javascript so probably I am asking something trivial, but I cannot see where there problem is. Or, better. Maybe I know where the problem is but I cannot find a...
3
by: John | last post by:
Hi I am looking for a sample database app that demonstrates how a reasonably written database app should look like in code. Any recommendations would be appreciated. Many Thanks Regards
0
by: TrevRex | last post by:
Hello, I work for a non-profit in San Diego as a GIS Specialist. I have had to teach myself about some scripting to create some dynamic maps, but I am still very limited in my skills, so I have...
5
by: Nike1984 | last post by:
I'm fairly new to Javascript and it's more of a guessing game for me... I'm trying to build an app for Google Maps and just had some issues recently. First off I just wanted to say that everything...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.