Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

PHP error when using a Java to output markers on Google Maps

Javascript coding ..

Moderators: macek, egami, gesf

PHP error when using a Java to output markers on Google Maps

Postby valleysboy » Thu Jan 19, 2012 9:19 am

Hi, I'm trying to output markers onto a Google Map (api v.3) using a tut I found http://tips4php.net/2010/10/use-php-mysql-and-google-map-api-v3-for-displaying-data-on-map/

When adding this to my page I'm getting Undefined index:errors.

I have changed the variables in the php part of the script to suit my database yet have left everything else alone, cant figure out why I'm still getting a blank map????

Please help....

My code with errors being shown at bottom;

Code: Select all
<script src="http://maps.google.com/maps/api/js?v=3&sensor=false" type="text/javascript"></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(0, 0),
 zoom: 14,
 mapTypeId: google.maps.MapTypeId.ROADMAP,
 mapTypeControl: false,
 mapTypeControlOptions: {
 style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
 },
 navigationControl: true,
 navigationControlOptions: {
 style: google.maps.NavigationControlStyle.SMALL
 }
 });
 <br />
<b>Notice</b>:  Undefined index:  name in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>73</b><br />
<br />
<b>Notice</b>:  Undefined index:  lng in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>75</b><br />
<br />
<b>Notice</b>:  Undefined index:  info in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>76</b><br />
addMarker(53.994709, ,'<b></b><br/>');
<br />
<b>Notice</b>:  Undefined index:  name in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>73</b><br />
<br />
<b>Notice</b>:  Undefined index:  lng in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>75</b><br />
<br />
<b>Notice</b>:  Undefined index:  info in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>76</b><br />
addMarker(53.985416, ,'<b></b><br/>');
<br />
<b>Notice</b>:  Undefined index:  name in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>73</b><br />
<br />
<b>Notice</b>:  Undefined index:  lng in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>75</b><br />
<br />
<b>Notice</b>:  Undefined index:  info in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>76</b><br />
addMarker(53.985416, ,'<b></b><br/>');
<br />
<b>Notice</b>:  Undefined index:  name in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>73</b><br />
<br />
<b>Notice</b>:  Undefined index:  lng in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>75</b><br />
<br />
<b>Notice</b>:  Undefined index:  info in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>76</b><br />
addMarker(0.000000, ,'<b></b><br/>');
<br />
<b>Notice</b>:  Undefined index:  name in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>73</b><br />
<br />
<b>Notice</b>:  Undefined index:  lng in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>75</b><br />
<br />
<b>Notice</b>:  Undefined index:  info in <b>D:\www\ofcftp\familysupport-results.php</b> on line <b>76</b><br />
addMarker(0.000000, ,'<b></b><br/>');
 center = bounds.getCenter();
 map.fitBounds(bounds);

 }
 </script>
valleysboy
New php-forum User
New php-forum User
 
Posts: 10
Joined: Thu Jan 19, 2012 9:04 am

Re: PHP error when using a Java to output markers on Google

Postby valleysboy » Fri Jan 20, 2012 8:44 am

Okay have got this to work but I'm still having trouble with putting php into java.

One line I have is

Code: Select all
var myLatLng = new google.maps.LatLng(-33.890542, 151.274856);


I want to echo the lat and long fields into this yet can't get the syntax right....

Code: Select all
var myLatLng = new google.maps.LatLng(<?php echo $lat; ?>, <?php echo $long; ?>);
valleysboy
New php-forum User
New php-forum User
 
Posts: 10
Joined: Thu Jan 19, 2012 9:04 am

Further update

Postby valleysboy » Thu Jan 26, 2012 7:50 am

Adding more php this time and used a different google js...

Code: Select all
<?php
$dbh = mysql_connect ('host', 'password', 'db');
@mysql_select_db ('ofc') or die ("Unable to select database");
$idnumber = $_GET['id'];
$sql_result = "SELECT * FROM family_support WHERE id = $idnumber";
$result =  mysql_query($sql_result, $dbh) or die ('Database currently being updated, please try again later!');
$i=0;
$org_name = mysql_result($result, $i, 'org_name');
$lat = mysql_result($result, $i, 'lat');
$long = mysql_result($result, $i, 'long');
?>

<!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>
<title><?php echo $org_name;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=false"></script> 
        <script type="text/javascript">
            var map;

            function initialize() {
              var myLatlng = new google.maps.LatLng('<? echo $lat; ?>','<? echo $lng; ?>');
              var myOptions = {
                zoom: 16,
                center: myLatlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
              }
              map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

              var marker = new google.maps.Marker({
                  position: myLatlng,
                  draggable: true,
                  flat: false,
                  map: map
              });

              google.maps.event.addListener(marker, 'dragend', function(event) {
                document.getElementById('lat').value =  marker.getPosition().lat();
                document.getElementById('lng').value =  marker.getPosition().lng();
              });
            }

            function placeMarker(location) {
              var clickedLocation = new google.maps.LatLng(location);
              var marker = new google.maps.Marker({
                  position: location,
                  draggable: true,
                  map: map
              });

              map.setCenter(location);
            }
    </script>
</head>
<body onload="initialize()">
<div id=map_canvas></div>
valleysboy
New php-forum User
New php-forum User
 
Posts: 10
Joined: Thu Jan 19, 2012 9:04 am


Return to JavaScript

Who is online

Users browsing this forum: No registered users and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.