PHP - Google Map Marker
hey guys how do i get a zip codes in the range of 50KM from the current search that is performed!! the search based on zipcodes.
and also is ti possible to print text ON the marker. Dynamic text. anyideas will be great thanks Similar TutorialsHi all
The issue is, I want to show a map on google map site with marker on the location, when someone click on the link on my site. The problem is map is showing correctly, but no marker is there. Here is the link I am using
<a href="https://www.google.c...803171">Map</a>
Any help ?
Hi, I currently have a google map which shows a marker where the postcode is for a certain pub (converts postcodes to coords lat/long) I would like to loop through all my pubs in my database as place a marker for each on one map, I am uncertain of how to loop through and show each marker for each postcode either PHP or JavaScript. here is my code for a single pub / postcode: Code: [Select] <!doctype html> <?php include "../config.php"; $loggedIn = (isset($_COOKIE['loggedin']) && $_COOKIE['loggedin'] == 'true')?true:false; $PUBID = intval($_REQUEST['PUBID']); $PUB = mysql_query("SELECT * FROM pubs WHERE PUBID = '".$PUBID."'"); $pubdetails = mysql_fetch_array($PUB); ?> <html> <head> <meta charset="UTF-8" /> <title><?php echo $pubdetails['rsPubName']; ?>, <?php echo $pubdetails['rsTown']; ?>, <?php echo $pubdetails['rsCounty']; ?></title> <style type="text/css" media="screen">@import "jqtouch/jqtouch.min.css";</style> <style type="text/css" media="screen">@import "themes/jqt/theme.min.css";</style> <script src="jqtouch/jquery.1.3.2.min.js" type="text/javascript" charset="utf-8"></script> <script src="jqtouch/jqtouch.min.js" type="application/x-javascript" charset="utf-8"></script> <script src="http://maps.google.com/maps?file=api&v=2&sensor=true&key=ABQIAAAAM17e4xGXwO4sBd_QYtRiSRQXB4T7UHWaz4zUQgLx9muJZW0c3hS8jRMJg733CHqOihn7BVfhZTkLiA" type="text/javascript"></script> <script type="text/javascript"> function initialize() { var latlng = new google.maps.LatLng(-34.397, 150.644); var myOptions = { zoom: 8, center: latlng, mapTypeId: google.maps.MapTypeId.G_NORMAL_MAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); } </script> <script type="text/javascript" charset="utf-8"> var jQT = new $.jQTouch({ icon: 'jqtouch.png', addGlossToIcon: false, startupScreen: 'jqt_startup.png', statusBar: 'black', preloadImages: [ 'themes/jqt/img/back_button.png', 'themes/jqt/img/back_button_clicked.png', 'themes/jqt/img/button_clicked.png', 'themes/jqt/img/grayButton.png', 'themes/jqt/img/whiteButton.png', 'themes/jqt/img/loading.gif' ] }); </script> </head> <body onLoad="ukPostcodeTest(); return false"> <!-- TOWNS --> <div id="pub" class="current"> <div class="toolbar"> <h1>View Pub</h1> <a class="back" href="index.php" rel="external">Home</a> </div> <h2><?php echo $pubdetails['rsPubName']; ?></h2> <?php echo $pubdetails['rsAddress']; ?><br /> <?php echo $pubdetails['rsTown']; ?><br /> <?php echo $pubdetails['rsCounty']; ?><br /> <?php echo $pubdetails['rsPostCode']; ?><br /> <?php echo $pubdetails['Region']; ?><br /> <?php echo $pubdetails['rsTel']; ?><br /> <?php echo '<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.mypubspace.com/pub_info.php?PUBID='.$pubdetails['PUBID'].'&layout=box_count&show_faces=true&width=450&action=like&colorscheme=light&height=65" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:60px; height:65px; float:right;" allowTransparency="true"></iframe>';?> <div id="map" style="width: 250px; height: 250px"></div> <form name="mapform" onsubmit="ukPostcodeTest(); return false" action="#"> <input id="search" type="hidden" value="<?php echo $pubdetails["rsPostCode"]; ?>" /> </form> <div id="message"></div> <noscript><b>JavaScript must be enabled in order for you to use Google Maps.</b> However, it seems JavaScript is either disabled or not supported by your browser. To view Google Maps, enable JavaScript by changing your browser options, and then try again. </noscript> <script type="text/javascript"> //<![CDATA[ if (GBrowserIsCompatible()) { var map = new GMap(document.getElementById("map")); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(51.520593197675446,-0.19775390625),16); // ====== Is the search string a UK Postcode ====== function ukPostcodeTest() { var search = document.getElementById("search").value; // take a copy and convert to upper case var s = search.toUpperCase(); // Replace punctuation and whitepsace by a single space s = s.replace(/\W+/g, " "); // Remove and trailing leading spaces s = s.replace(/^ /, ""); s = s.replace(/ $/, ""); // Perform the check var match = s.match(/^[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}$/); if (!match) { // Its not a UK Postcode, so perform a standard GClientGeocoder call on the original search string showAddress(search); } else { // It is a UK Postcode, so call GDirections on the reformatted search string showPostcode(s); } } // ====== Code for handling search strings that are not UK Postcodes ======= // ====== Use the GClientGeocoder in the normal way ====== // ====== Create a Client Geocoder ====== var geo = new GClientGeocoder(); // ====== Array for decoding the failure codes ====== var reasons=[]; reasons[G_GEO_SUCCESS] = "Success"; reasons[G_GEO_MISSING_ADDRESS] = "Missing Address: The address was either missing or had no value."; reasons[G_GEO_UNKNOWN_ADDRESS] = "Unknown Address: No corresponding geographic location could be found for the specified address."; reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address: The geocode for the given address cannot be returned due to legal or contractual reasons."; reasons[G_GEO_BAD_KEY] = "Bad Key: The API key is either invalid or does not match the domain for which it was given"; reasons[G_GEO_TOO_MANY_QUERIES] = "Too Many Queries: The daily geocoding quota for this site has been exceeded."; reasons[G_GEO_SERVER_ERROR] = "Server error: The geocoding request could not be successfully processed."; // ====== Geocoding ====== function showAddress(search) { // ====== Perform the Geocoding ====== geo.getLocations(search, function (result) { // If that was successful if (result.Status.code == G_GEO_SUCCESS) { // How many resuts were found document.getElementById("message").innerHTML = "Found " +result.Placemark.length +" results"; // Loop through the results, placing markers for (var i=0; i<result.Placemark.length; i++) { var p = result.Placemark[i].Point.coordinates; var marker = new GMarker(new GLatLng(p[1],p[0])); document.getElementById("message").innerHTML += "<br>"+(i+1)+": "+ result.Placemark[i].address + marker.getPoint(); map.addOverlay(marker); } // centre the map on the first result var p = result.Placemark[0].Point.coordinates; map.setCenter(new GLatLng(p[1],p[0]),14); } // ====== Decode the error status ====== else { var reason="Code "+result.Status.code; if (reasons[result.Status.code]) { reason = reasons[result.Status.code] } alert('Could not find "'+search+ '" ' + reason); } } ); } // ====== Create a Client Geocoder ====== var gdir = new GDirections(null); // ====== Using GDirections to process a UK postcode ====== function showPostcode(search) { // Call GDirections gdir.loadFromWaypoints([search,search],{getPolyline:true}); // Wait for the reply to come back GEvent.addListener(gdir,"load", function() { var poly = gdir.getPolyline(); var point = poly.getVertex(0); //document.getElementById("message").innerHTML = "Found a UK Postcode"; // Process the result var marker = new GMarker(point); //document.getElementById("message").innerHTML += "<br>" + search + " = " + point.toUrlValue(5); map.addOverlay(marker); // centre the map on the result map.setCenter(point,16); }); } } // display a warning if the browser was not compatible else { alert("Sorry, the Google Maps API is not compatible with this browser"); } // This Javascript is based on code provided by the // Community Church Javascript Team // http://www.bisphamchurch.org.uk/ // http://econym.org.uk/gmap/ //]]> </script> </div> </body> </html> Help me...
My objective is to reload the marker inside google map every 30s...
But the scripts below seem not running properly...
<?php define('INCLUDE_CHECK',1); include "dbconnect.php"; ?> <!DOCTYPE html> <html lang="en"> <head> <title></title> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name ="audience" CONTENT="all"> <meta name ="revisit-after" CONTENT="4 days"> <meta name ="content-Language" CONTENT="English"> <meta name ="distribution" CONTENT="global"> <link rel="shortcut icon" href="favicon.png"/> <link rel="stylesheet" type="text/css" href="host_entry/css/demo.css" /> <link href="host_entry/css/bootstrap.min.css" rel="stylesheet" media="screen"> <script type="text/javascript" src="host_entry/js/jquery-1.7.1.min.js"></script> <script src="host_entry/js/bootstrap.min.js"></script> <!-- Google Map JS --> <script src="http://maps.google.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false" type="text/javascript"></script> <script> //SCRIPTS TO RESFRESH THE MARKER...I THINK THIS IS INCORRECT...HELP!!! $(document).ready(function() { $.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh setInterval(function() { $('#result').load('index.php'); }, 10000); // the "3000" here refers to the time to refresh the div. it is in milliseconds. }); // ]]> </script> </head> //to dislay the map <div id="map_canvas" style="top:55px;left:13px;"> <!-- Map will display --> <div id="map"> <!-- Fullscreen Loading & Fullscreen Buttons area --> <span style="color:Gray;">Loading map...</span> </div> <!-- Fullscreen Loading & Fullscreen Buttons area Ends --> </div><!-- Map Ends display --> <script type="text/javascript"> var locations = [ <?php $query="SELECT * from host_entry"; $result=mysql_query($query)or die(mysql_error()); { if ($num=mysql_numrows($result)) { $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); //$host_type=mysql_result($result,$i,"host_type"); $host_name=mysql_result($result,$i,"host_name"); $host_status=mysql_result($result,$i,"host_status"); $host_lapt=mysql_result($result,$i,"host_lapt"); $host_long=mysql_result($result,$i,"host_long"); if($host_status==0) echo "[ '<div id=result><div class=info style=text-align:center;><h4>$host_name</h4></div></div>', $host_lapt, $host_long],"; $i++; } }else { echo "<h3 align='center'><font color='#ff0000'>No Content Found</font></h3>"; } } ?> ]; //FROM HERE TO SET THE MARKER IMAGE // Setup the different icons and shadows var iconURLPrefix = 'host_entry/img/'; var icons = [ iconURLPrefix + 'p_red_alert.png' ] var icons_length = icons.length; var map = new google.maps.Map(document.getElementById('map'), { zoom: -5, center: new google.maps.LatLng(3.1215681, 101.71180140000001), mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: false, streetViewControl: false, disableDefaultUI: true, panControl: false, zoomControlOptions: { position: google.maps.ControlPosition.LEFT_BOTTOM } }); var infowindow = new google.maps.InfoWindow({ maxWidth: 400, maxHeight: 350, }); var marker; var markers = new Array(); var iconCounter = 0; //I THINK THE PROBLEM START HERE...:( // Add the markers and infowindows to the map for (var i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i][1], locations[i][2], locations[i][3], locations[i][4], locations[i][5]), map: map, animation: google.maps.Animation.BOUNCE, icon : icons[iconCounter], }); markers.push(marker); google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { infowindow.setContent(locations[i][0]); infowindow.open(map, marker); } })(marker, i)); iconCounter++; // We only have a limited number of possible icon colors, so we may have to restart the counter if(iconCounter >= icons_length){ iconCounter = 0; } } function AutoCenter() { // Create a new viewpoint bound var bounds = new google.maps.LatLngBounds(); // Go through each... $.each(markers, function (index, marker) { bounds.extend(marker.position); }); // Fit these bounds to the map map.fitBounds(bounds); } AutoCenter(); google.maps.event.addDomListener(window, 'load', initialize); </script> <?php //include "includes/footer.php"; ?> </body> </html>Is there a way to reload the marker with the ability of ajax towards the markers Help me for the solution... Thanks.... HI guys, On my site users are enabled to see the location of other users they are trying to find, but i want to add a link to that all users profiles on the window of their marker. Below is the code for the map. The link would be coded something like Code: [Select] <a href="userprofile.php?id=<?php echo $row['id'];?>"> im not sure if this is or the correct approach . I would thnk that it would have to be added to the create marker function... but i can get it to work Any help would be appreciated. Code: [Select] <script type="text/javascript"> //<![CDATA[ var iconBlue = new GIcon(); iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png'; iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'; iconBlue.iconSize = new GSize(12, 20); iconBlue.shadowSize = new GSize(22, 20); iconBlue.iconAnchor = new GPoint(6, 20); iconBlue.infoWindowAnchor = new GPoint(5, 1); var iconRed = new GIcon(); iconRed.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png'; iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'; iconRed.iconSize = new GSize(12, 20); iconRed.shadowSize = new GSize(22, 20); iconRed.iconAnchor = new GPoint(6, 20); iconRed.infoWindowAnchor = new GPoint(5, 1); var customIcons = []; customIcons["restaurant"] = iconBlue; customIcons["bar"] = iconRed; function load() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(51.89787, -8.47109), 13); GDownloadUrl("geo.php", function(data) { var xml = GXml.parse(data); var markers = xml.documentElement.getElementsByTagName("marker"); for (var i = 0; i < markers.length; i++) { var name = markers[i].getAttribute("name"); var address = markers[i].getAttribute("address"); var type = markers[i].getAttribute("type"); var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng"))); var marker = createMarker(point, name, address, type); map.addOverlay(marker); } }); } } function createMarker(point, name, address, type) { var marker = new GMarker(point, customIcons[type]); var html = "<b>" + name + "</b><br/>" + address; GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(html); }); return marker; } //]]> Hi! I have this code <?php /** * @Project: Virtual Airlines Manager (VAM) * @Author: Alejandro Garcia * @Web http://virtualairlinesmanager.net * Copyright (c) 2013 - 2016 Alejandro Garcia * VAM is licensed under the following license: * Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) * View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/4.0/ */ ?> <!DOCTYPE html> <html> <head> <script src="https://maps.googleapis.com/maps/api/js?key=XXX&callback=initMap" type="text/javascript"> </script> <meta http-equiv="refresh" content="300"> </head> <body> <?php include('./db_login.php'); $db_map = new mysqli($db_host , $db_username , $db_password , $db_database); $db_map->set_charset("utf8"); if ($db_map->connect_errno > 0) { die('Unable to connect to database [' . $db_map->connect_error . ']'); } $sql_map = "select plane_type,ias,flight_id,u.gvauser_id as gvauser_id,u.callsign as callsign,u.name as name,gs,altitude,surname,departure,arrival,latitude,longitude,flight_status,heading,perc_completed, pending_nm, a1.latitude_deg as dep_lat, a1.longitude_deg as dep_lon , a2.latitude_deg as arr_lat, a2.longitude_deg as arr_lon , network from vam_live_flights lf, gvausers u , airports a1, airports a2 where u.gvauser_id=lf.gvauser_id and lf.departure=a1.ident and lf.arrival=a2.ident"; if (!$result = $db_map->query($sql_map)) { die('There was an error running the query [' . $db_map->error . ']'); } unset($flights_coordinates); unset($flight); unset($liveflights); unset($datos); unset($jsonarray); $flights_coordinates = array(); $datos = array (); $flight = array(); $liveflights = array (); $jsonarray = array (); $index = 0; $index2=0; $flightindex=0; while ($row = $result->fetch_assoc()) { $flight["gvauser_id"]=$row["gvauser_id"]; $flight["callsign"]=$row["callsign"]; $flight["name"]=$row["name"]; $flight["gs"]=$row["gs"]; $flight["ias"]=$row["ias"]; $flight["altitude"]=$row["altitude"]; $flight["surname"]=$row["surname"]; $flight["departure"]=$row["departure"]; $flight["arrival"]=$row["arrival"]; $flight["latitude"]=$row["latitude"]; $flight["longitude"]=$row["longitude"]; $flight["flight_status"]=$row["flight_status"]; $flight["heading"]=$row["heading"]; $flight["dep_lat"]=$row["dep_lat"]; $flight["dep_lon"]=$row["dep_lon"]; $flight["arr_lat"]=$row["arr_lat"]; $flight["arr_lon"]=$row["arr_lon"]; $flight["perc_completed"]=$row["perc_completed"]; $flight["pending_nm"]=$row["pending_nm"]; $flight["network"]=$row["network"]; $flight["plane_type"]=$row["plane_type"]; $liveflights[$flightindex] =$flight; $sql_map2 = "select * from vam_live_acars where flight_id='".$row["flight_id"]."' order by id asc"; if (!$result2 = $db_map->query($sql_map2)) { die('There was an error running the query [' . $db_map->error . ']'); } while ($row2 = $result2->fetch_assoc()) { $flights_coordinates ["gvauser_id"] = $row2["gvauser_id"]; $flights_coordinates ["latitude"] = $row2["latitude"]; $flights_coordinates ["longitude"] = $row2["longitude"]; $flights_coordinates ["heading"] = $row2["heading"]; $datos [$index2][$index] = $flights_coordinates; $index ++; } $index=0 ; $index2 ++; $flightindex ++; } $jsonarray[0]=$liveflights; $jsonarray[1]=$datos; ?> <div class="container"> <div class="row"> <div id="map-outer" class="col-md-11"> <div id="map-container" class="col-md-12"></div> <div id="over_map"></div> </div><!-- /map-outer --> </div> <!-- /row --> </div><!-- /container --> <style> body { background-color:#FFFFF } #map-outer { padding: 0px; border: 0px solid #CCC; margin-bottom: 0px; background-color:#FFFFF } #map-container { height: 500px } @media all and (max-width: 800px) { #map-outer { height: 650px } } </style> <style> #wrapper { position: relative; } #over_map { position: absolute; top: 50px; left: 10px; z-index: 99; background: white;} </style> </body> <script type="text/javascript"> var mapCentre; var map ; function init_map() { var flights = <?php echo json_encode($jsonarray[0]); ?>; var locations = <?php echo json_encode($jsonarray[1]); ?>; var numpoints=(locations.length); console.log(locations); var var_location = new google.maps.LatLng(<?php echo $datos[0][0]["latitude"]; ?>,<?php echo $datos[0][0]["longitude"]; ?>); var var_mapoptions = { center: var_location, zoom: 5, styles: [{"featureType":"all","elementType":"all","stylers":[{"saturation":"0"},{"lightness":"0"}]},{"featureType":"all","elementType":"geometry","stylers":[{"lightness":"20"}]},{"featureType":"administrative","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"administrative","elementType":"geometry.stroke","stylers":[{"visibility":"on"}]},{"featureType":"administrative","elementType":"labels","stylers":[{"visibility":"on"},{"color":"#716464"},{"weight":"0.01"}]},{"featureType":"administrative.country","elementType":"labels","stylers":[{"visibility":"on"}]},{"featureType":"landscape","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"landscape.natural","elementType":"geometry","stylers":[{"visibility":"simplified"}]},{"featureType":"landscape.natural.landcover","elementType":"geometry","stylers":[{"visibility":"simplified"}]},{"featureType":"poi","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"poi","elementType":"geometry.fill","stylers":[{"visibility":"simplified"}]},{"featureType":"poi","elementType":"geometry.stroke","stylers":[{"visibility":"simplified"}]},{"featureType":"poi","elementType":"labels.text","stylers":[{"visibility":"simplified"}]},{"featureType":"poi","elementType":"labels.text.fill","stylers":[{"visibility":"simplified"}]},{"featureType":"poi","elementType":"labels.text.stroke","stylers":[{"visibility":"simplified"}]},{"featureType":"poi.attraction","elementType":"geometry","stylers":[{"visibility":"on"}]},{"featureType":"road","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"road","elementType":"labels","stylers":[{"visibility":"on"}]},{"featureType":"road.highway","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"road.highway","elementType":"geometry","stylers":[{"visibility":"on"}]},{"featureType":"road.highway","elementType":"geometry.fill","stylers":[{"visibility":"on"},{"color":"#ffad99"},{"lightness":"45"}]},{"featureType":"road.highway","elementType":"geometry.stroke","stylers":[{"visibility":"on"},{"color":"#fbac99"},{"lightness":"1"}]},{"featureType":"road.highway","elementType":"labels","stylers":[{"visibility":"on"}]},{"featureType":"road.highway.controlled_access","elementType":"geometry.fill","stylers":[{"color":"#ffff80"},{"lightness":"50"}]},{"featureType":"road.highway.controlled_access","elementType":"geometry.stroke","stylers":[{"color":"#ff6666"},{"lightness":"59"},{"visibility":"on"},{"weight":"1.10"}]},{"featureType":"road.arterial","elementType":"geometry.fill","stylers":[{"visibility":"on"},{"color":"#fff13a"}]},{"featureType":"road.arterial","elementType":"geometry.stroke","stylers":[{"color":"#f2d344"},{"visibility":"off"},{"weight":"1.41"}]},{"featureType":"road.local","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"transit","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"transit","elementType":"geometry","stylers":[{"visibility":"simplified"}]},{"featureType":"transit.station","elementType":"geometry","stylers":[{"visibility":"on"}]},{"featureType":"water","elementType":"all","stylers":[{"visibility":"simplified"},{"color":"#12586f"},{"lightness":"20"},{"gamma":"6.95"},{"saturation":"-29"}]},{"featureType":"water","elementType":"geometry","stylers":[{"visibility":"on"}]},{"featureType":"water","elementType":"geometry.fill","stylers":[{"visibility":"on"}]}] }; map = new google.maps.Map(document.getElementById('map-container'), var_mapoptions); var mapas=[]; var flightPlanCoordinates=[]; var flightPath = new google.maps.Polyline({ strokeColor: "#c3524f", strokeOpacity: 1, strokeWeight: 2, geodesic: true }); var k=0; var z=0; var coordinate; while (k<numpoints) { while (z < locations[k].length) { coordinate =new google.maps.LatLng(locations[k][z]['latitude'],locations[k][z]['longitude']); flightPlanCoordinates.push(coordinate); z=z+1; } ruta = new google.maps.Polyline({ geodesic: true, strokeColor: '#FF0000', strokeOpacity: 1.0, strokeWeight: 2 }); ruta.setPath(flightPlanCoordinates); mapas.push(ruta); z=0; k=k+1; }; function createMarker(pos, t) { var coord=[]; var pathcoord=[]; var flight_id = t; currentPath = new google.maps.Polyline({ geodesic: true, strokeColor: '#FF0000', strokeOpacity: 1.0, strokeWeight: 2 }); // Plane marker begin var image = new google.maps.MarkerImage("./map_icons/"+flights[t]['heading'] +".png",null,new google.maps.Point(0,0),new google.maps.Point(15, 15),new google.maps.Size(30, 30)); var icon_airport = new google.maps.MarkerImage("./map_icons/airport_yellow_marker.png"); var lineSymbol = {path: 'M 0,-1 0,1', strokeOpacity: 1, scale: 1 }; var lat1 = flights[t]["dep_lat"]; var lat2 = flights[t]["arr_lat"]; var lng1 = flights[t]["dep_lon"]; var lng2 = flights[t]["arr_lon"]; var dep = new google.maps.LatLng(lat1, lng1) var arr = new google.maps.LatLng(lat2, lng2) var icon_plane = 'images/plane.png'; var marker = new google.maps.Marker({ position: pos, icon: image, name: t , contenido: flights[t]['callsign']+ ' '+flights[t]['name']+ ' '+flights[t]['surname'] , icao1:new google.maps.Marker({ position: dep, map: map, icon: icon_airport, visible: false }), icao2:new google.maps.Marker({ position: arr, map: map, icon: icon_airport, visible: false }), line1:new google.maps.Polyline({ path: [dep, pos], strokeColor: "#08088A", strokeOpacity: 1, strokeWeight: 2, geodesic: true, map: map, polylineID: t, visible: false }) , line2:new google.maps.Polyline({ path: [pos, arr], strokeColor: "#FE2E2E", strokeOpacity: .3, geodesic: true, map: map, icons: [{ icon: lineSymbol, offset: '0', repeat: '5px' }], polylineID: t, visible: false }) }); // On mouse over google.maps.event.addListener(marker, 'mouseover', function () { //infowindow.open(map, marker); this.get('line1').setVisible(true); this.get('line2').setVisible(true); this.get('icao1').setVisible(true); this.get('icao2').setVisible(true); infowindow.open(map,marker); infowindow.setContent(marker.contenido); var s=0; coord.length = 0; pathcoord.length = 0; while (s < locations[flight_id].length) { coord= new google.maps.LatLng(locations[flight_id][s]['latitude'],locations[flight_id][s]['longitude']); pathcoord.push(coord); s=s+1; } currentPath.setPath(pathcoord); currentPath.setMap(map); }); // On mouse end // mouse out google.maps.event.addListener(marker, 'mouseout', function () { //infowindow.close(); //this.get('line1').setVisible(false); //this.get('line2').setVisible(false); //this.get('icao1').setVisible(false); //this.get('icao2').setVisible(false); //currentPath.setMap(null); }); // mouse out end // On Click begin google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); infowindow.setContent(marker.contenido); var s=0; coord.length = 0; pathcoord.length = 0; while (s < locations[flight_id].length) { coord= new google.maps.LatLng(locations[flight_id][s]['latitude'],locations[flight_id][s]['longitude']); pathcoord.push(coord); s=s+1; } currentPath.setPath(pathcoord); currentPath.setMap(map); if (this.get('line1').visible ='true') { this.get('line1').setVisible(false); } if (this.get('line2').visible ='true') { this.get('line2').setVisible(false); } if (this.get('icao1').visible ='true') { this.get('icao1').setVisible(false); } if (this.get('icao2').visible ='true') { this.get('icao2').setVisible(false); } flight_detail='<div class="panel panel-map">\ <!-- Default panel contents -->\ <div class=\"panel-heading\">'+flights[t]['departure'] + ' <i class="fa fa-arrow-right"></i> ' + flights[t]['arrival']+'</div>\ <table class="table-map">\ <tr>\ <td><small>Flight completed</small><br><div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="\ '+flights[t]['perc_completed'] + '" aria-valuemin="0" aria-valuemax="100" style="width:'+flights[t]['perc_completed']+'%">\ '+flights[t]['perc_completed'] + ' %</div></td>\ </tr>\ <tr>\ <td><small>Callsign</small><br><strong>\ '+flights[t]['callsign'] + '</strong></td>\ </tr>\ <tr>\ <td><small>Flight Status</small><br><strong>\ '+flights[t]['flight_status'] + '</strong></td>\ </tr>\ <tr>\ <td><small>Plane Type</small><br><strong>\ '+flights[t]['plane_type'] + '</strong></td>\ </tr>\ <tr>\ <td><small>Network</small><br><strong>\ '+flights[t]['network'] + '</strong></td>\ </tr>\ <tr>\ <td><small>Pending NM</small><br><strong>\ '+flights[t]['pending_nm'] + '</strong></td>\ </tr>\ <tr>\ <td><small>GS</small><br><strong>\ '+flights[t]['gs'] + '</strong></td>\ </tr>\ <tr>\ <td><small>IAS</small><br><strong>\ '+flights[t]['ias'] + '</strong></td>\ </tr>\ <tr>\ <td><small>Altitude</small><br><strong>\ '+flights[t]['altitude'] + '</strong></td>\ </tr>\ <tr>\ <td><small>Heading</small><br><strong>\ '+flights[t]['heading'] + '</strong></td>\ </tr>\ </table>\ </div>'; //flights[t]['departure'] + '-' + flights[t]['arrival'] + '<br />' + flights[t]['callsign']+ ' '+flights[t]['name']+ ' '+flights[t]['surname'] + '<br />' + 'ALTITUDE: ' + flights[t]['altitude'] + '<br />' + 'GS: ' + flights[t]['gs']+ '<br />' + 'HEADING: ' + flights[t]['heading'] + '<br />' + flights[t]['flight_status']; $('#over_map').html("<div id='mySecondDiv'>"+flight_detail+"</div>"); }); // On Click end return marker; } var numflight=0 while (numflight < flights.length ) { var avionicon =new google.maps.LatLng(flights[numflight]['latitude'],flights[numflight]['longitude']); var m1 = createMarker(avionicon, numflight); m1.setMap(map); numflight = numflight +1; } var s=0; while (s < mapas.length) { s=s+1; } var infowindow = new google.maps.InfoWindow({ }); google.maps.event.addListener(infowindow, 'closeclick', function() { $('#over_map').html(""); }); } google.maps.event.addDomListener(window, 'load', init_map); $( document ).ready(refreshflights); function refreshflights(){ setInterval(function () {$.ajax({ url: 'get_map_coordinates.php', data: "", dataType: 'json', success: function(data, textStatus, jqXHR) { init_map(); } })}, 120000); } </script> </html> I need map to be centered on marker every time i go on my webpage. Right now is centered on deparrture aiport. So this is map for flights, as flight is ongoing , aircraft (marker) on route, map should be tracking it so every time i refresh my wepage, map should point to marker, not to departure airport. Can anyone halp me. Thank you Edited December 23, 2020 by mrshiljoI've been pulling my hair out for the past couple of hours working with simplexml_load_file(). I was attempting to consume a web service generated by asp.net that I've been consuming using CURL and a function to remove the BOM (byte order marker) so that I could load it into simplexml_load_string(). When I switched over to simplexml_load_file() to call the file instead of using CURL and my function, I was getting errors that it could not find the beginning '<' and that the document was empty and so on.. I couldn't find anything about simplexml_load_file() handling BOM characters, so I went for a walk. I came back to my desk and refreshed the page.. and it just started working. I changed nothing! Guess I should be happy that it started working, but I'd sure like to know why it was breaking in the first place, and then why it would suddenly start working without me doing anything. Has anyone else seen anything like this? Hey guys, I have stored a google map link into a database. When I try to display it from database using the command below <?php echo $google_map; ?> I get this output, but I can't display a map. Code: [Select] <iframe width="640" height="480" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&source=s_q&hl=hr&geocode=&q=smi%C4%8Diklasova+3,+karlovac,+croatia&sll=37.0625,-95.677068&sspn=50.910968,135.263672&ie=UTF8&hq=&hnear=Tadije+Smi%C4%8Diklasa,+Karlovac,+Republika+Hrvatska&t=h&ll=45.487155,15.55089&spn=0.028883,0.054932&z=14&iwloc=A&output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&source=embed&hl=hr&geocode=&q=smi%C4%8Diklasova+3,+karlovac,+croatia&sll=37.0625,-95.677068&sspn=50.910968,135.263672&ie=UTF8&hq=&hnear=Tadije+Smi%C4%8Diklasa,+Karlovac,+Republika+Hrvatska&t=h&ll=45.487155,15.55089&spn=0.028883,0.054932&z=14&iwloc=A" style="color:#0000FF;text-align:left">Prikaz veće karte</a></small> Can you tell me why?? When try to copy that directly to HTML it works perfectly!!! I'm confused! Hi guys Mods please move if this is the wrong place to ask. I have a google maps api added to my web site but i want to be able to position "pins" on the map to show all the the registered clubs in an area... eg the user searches dublin and all teh clubs pop up... My question is.. is there anyway to do this without needing the user to supply the long/lat.. ie can it be gotten automatically?? I really just want it to work off the addrees/area they supplied when they registered. thanks tt I'm having trouble loading this kind of KML with PHP http://code.google.com/apis/maps/documentation/mapsdata/developers_guide_protocol.html#RetrievingFeatures example <atom:entry xmlns='http://www.opengis.net/kml/2.2' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:gd='http://schemas.google.com/g/2005'> <atom:id> http://maps.google.com/maps/feeds/features/userID/mapID/full/featureID</atom:id> <atom:published>2008-08-14T17:46:06.462Z</atom:published> <atom:updated>2008-08-14T18:12:31.589Z</atom:updated> <atom:category scheme='http://schemas.google.com/g/2005#kind' ..... it seems like the column in atom:entry, etc is causing this. $response = simplexml_load_string($response); print_r($response); the above just gives an empty SimpleXMLElement Object() Any ideas For every search, I get ZERO RESULTS, and I don't understand what I'm doing wrong. Code: [Select] <?php require('places_class.php'); $types = $_POST['type']; $location = $_POST['place']; $radius = $_POST['radius']; $gplaces = New GooglePlaces; $gplaces->SetLocation("$location"); $gplaces->SetRadius($radius); $gplaces->SetTypes("$types"); $results = $gplaces->Search(); print_r($results); ?> That's when the form is submitted, I checked the variables, and they are echoing out correctly. Then I thought I'd hard-code the values in, same results Code: [Select] <?php require('places_class.php'); $gplaces = New GooglePlaces; $gplaces->SetLocation("40.5267,81.4778"); $gplaces->SetRadius(50); $gplaces->SetTypes("food"); $results = $gplaces->Search(); print_r($results); ?> Here is the class Code: [Select] <?php class GooglePlaces { private $APIKey = ""; public $OutputType = "json"; //either json, xml or array public $Errors = array(); private $APIUrl = "https://maps.googleapis.com/maps/api/place"; private $APICallType = ""; private $IncludeDetails = false; //all calls private $Language = 'en'; //optional - https://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1 //Search private $Location; //REQUIRED - This must be provided as a google.maps.LatLng object. private $Radius; //REQUIRED private $Types; //optional - separate tyep with pipe symbol http://code.google.com/apis/maps/documentation/places/supported_types.html private $Name; //optional //Search, Details, private $Sensor = 'false'; //REQUIRED - is $Location coming from a sensor? like GPS? //Details & Delete private $Reference; //Add private $Accuracy; public function Search() { $this->APICallType = "search"; return $this->APICall(); } public function Details() { $this->APICallType = "details"; return $this->APICall(); } public function Checkin() { $this->APICallType = "checkin-in"; return $this->APICall(); } public function Add() { $this->APICallType = "add"; return $this->APICall(); } public function Delete() { $this->APICallType = "delete"; return $this->APICall(); } public function SetLocation($Location) { $this->Location = $Location; } public function SetRadius($Radius) { $this->Radius = $Radius; } public function SetTypes($Types) { $this->Types = $Types; } public function SetLanguage($Language) { $this->Language = $Language; } public function SetName($Name) { $this->Name = $Name; } public function SetSensor($Sensor) { $this->Sensor = $Sensor; } public function SetReference($Reference) { $this->Reference = $Reference; } public function SetAccuracy($Accuracy) { $this->Accuracy = $Accuracy; } public function SetIncludeDetails($IncludeDetails) { $this->IncludeDetails = $IncludeDetails; } private function CheckForErrors() { if(empty($this->APICallType)) { $this->Errors[] = "API Call Type is required but is missing."; } if(empty($this->APIKey)) { $this->Errors[] = "API Key is is required but is missing."; } if(($this->OutputType!="json") && ($this->OutputType!="xml") && ($this->OutputType!="json")) { $this->Errors[] = "OutputType is required but is missing."; } } private function APICall() { $this->CheckForErrors(); if($this->APICallType=="add" || $this->APICallType=="delete") { $URLToPostTo = $this->APIUrl."/".$this->APICallType."/".$this->OutputType."?key=".$this->APIKey."&sensor=".$this->Sensor; if($this->APICallType=="add") { $LocationArray = explode(",", $this->Location); $lat = trim($LocationArray[0]); $lng = trim($LocationArray[1]); $paramstopost[location][lat] = $lat; $paramstopost[location][lng] = $lng; $paramstopost[accuracy] = $this->Accuracy; $paramstopost[name] = $this->Name; $paramstopost[types] = explode("|", $this->Types); $paramstopost[language] = $this->Language; } if($this->APICallType=="delete") { $paramstopost[reference] = $this->Reference; } $result = json_decode($this->CurlCall($URLToPostTo,json_encode($paramstopost))); $result->errors = $this->Errors; return $result; } if($this->APICallType=="search") { $URLparams = "location=".$this->Location."&radius=".$this->Radius."&types=".$this->Types."&language=".$this->Language."&name=".$this->Name."&sensor=".$this->Sensor; } if($this->APICallType=="details") { $URLparams = "reference=".$this->Reference."&language=".$this->Language."&sensor=".$this->Sensor; } if($this->APICallType=="check-in") { $URLparams = "reference=".$this->Reference."&language=".$this->Language."&sensor=".$this->Sensor; } $URLToCall = $this->APIUrl."/".$this->APICallType."/".$this->OutputType."?key=".$this->APIKey."&".$URLparams; $result = json_decode(file_get_contents($URLToCall),true); $result[errors] = $this->Errors; if($result[status]=="OK" && $this->APICallType=="details") { foreach($result[result][address_components] as $key=>$component) { if($component[types][0]=="street_number") { $address_street_number = $component[short_name]; } if($component[types][0]=="route") { $address_street_name = $component[short_name]; } if($component[types][0]=="locality") { $address_city = $component[short_name]; } if($component[types][0]=="administrative_area_level_1") { $address_state = $component[short_name]; } if($component[types][0]=="postal_code") { $address_postal_code = $component[short_name]; } } $result[result][address_fixed][street_number] = $address_street_number; $result[result][address_fixed][address_street_name] = $address_street_name; $result[result][address_fixed][address_city] = $address_city; $result[result][address_fixed][address_state] = $address_state; $result[result][address_fixed][address_postal_code] = $address_postal_code; } return $result; } private function CurlCall($url,$topost) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $topost); $body = curl_exec($ch); curl_close($ch); return $body; } } ?> And yes, I do have the correct API Key, I just took it out Can anybody see what the issue is? Hi Guys!! I am in need of creating a categories' listing similar to that of Google Directory, http://www.google.com/dirhp All the categories along with their respective sub categories, subcategories of the subcategories, and the subsub categories of the subsub categories ( as deep down as the category system goes ) should be displayed which is exactly similar to that of the Google Directory. Could anyone suggest me how to do it as am pretty much new to PHP. The categories list is stored in a database and should be displayed using PHP and MySQL. This is exactly what i require. I have gone through some articles related to this, (both in this forum and elsewhere) but in all those tutorials, the depth of the categories is known (say, up to 4 or 5 levels). But, what i require is dynamic creation of these categories whose depth is unknown and also provide a way that any user can add a category from the front-end and also the admin can add a category from the back-end. Am in urgent need of this. Can anyone guide me in this regard, pls? And an example of the same would be of great help. Thanks in advance!! Is there a Chrome tag like this IE one <!--[if IE]> <![endif]--> <!--[if !IE]><!--> <!--<![endif]--> I have use the above tag in my wordpress site, and the only browser it doesn't work in is Google Chrome. Hi I'm using a the following google Pie Cart from here http://code.google.com/apis/ajax/playground/#pie_chart I would like to use php to COUNT printers listed in a column called machine and return result so I can echo it into google code Example of Column below would return a count of one for each except for the TurboJet which would return two. I would then like to echo the results to the google Javascript for printer 1 to 6. _______ machine ________ FB7500-1 TurboJet XL1500-1 Roland Canon TurboJet Can anyone help? Cheers Chris Code: [Select] <?php mysql_connect("localhost","chris","Cr2baxKUHWGxr6nn"); @mysql_select_db("schedule") or die( "Unable to select database"); date_default_timezone_set('Europe/London'); $query = "SELECT machine, COUNT(machine) FROM maindata GROUP BY machine"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "There are is ". $row['COUNT(machine)'] ." ". $row['machine'] ." items."; echo "<br />"; } ?> <!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 Visualization API Sample </title> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load('visualization', '1', {packages: ['corechart']}); </script> <script type="text/javascript"> function drawVisualization() { // Create and populate the data table. var data = new google.visualization.DataTable(); data.addColumn('string', 'Task'); data.addColumn('number', 'Hours per Day'); data.addRows(5); data.setValue(0, 0, 'Printer 1'); data.setValue(0, 1, 11); data.setValue(1, 0, 'Printer 2'); data.setValue(1, 1, 2); data.setValue(2, 0, 'Printer 4'); data.setValue(2, 1, 2); data.setValue(3, 0, 'Printer 5'); data.setValue(3, 1, 2); data.setValue(4, 0, 'Printer 6'); data.setValue(4, 1, 7); // Create and draw the visualization. new google.visualization.PieChart(document.getElementById('visualization')). draw(data, {title:"Current Work in Progress"}); } google.setOnLoadCallback(drawVisualization); </script> </head> <body style="font-family: Arial;border: 0 none;"> <div id="visualization" style="width: 600px; height: 400px;"></div> </body> </html> Hello to all. Please I need your help.
I have a web site (php, mysql, dreamweaver) with some seller info in a db table. They want to show a google map with their location of address, that have in the db. Let's say:
Field: Data:
tbAddress 22 Kastelliou street
tbPO 11141
tbLocal Athens
tbCountry Greece
I am try with these iframes that google has on site but this embed is ONLY for what i will find through the address bar. The dynamic web page I have, has the info of the seller (who, where, what) and I want this map dynamically change location, according to the address of the seller from the fields I provided.
Thank you
Hey all
I'm working on a script which needs to connect to the Google Calendar API, but when I run the code I get
Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }'' in /home/public_html/cal_test/google-api-php/src/Google/Auth/OAuth2.php:341 Stack trace: #0 /home/public_html/cal_test/google-api-php/src/Google/Auth/OAuth2.php(300): Google_Auth_OAuth2->refreshTokenRequest(Array) #1 /home/public_html/cal_test/google-api-php/src/Google/Auth/OAuth2.php(230): Google_Auth_OAuth2->refreshTokenWithAssertion() #2 /home/public_html/cal_test/google-api-php/src/Google/Service/Resource.php(171): Google_Auth_OAuth2->sign(Object(Google_Http_Request)) #3 /home/public_html/cal_test/google-api-php/src/Google/Service/Calendar.php(1133): Google_Service_Resource->call('list', Array, 'Google_Service_...') #4 /home/public_html/cal_test/index.php(34): Google_Service_Calendar_CalendarList_Resource->listCalendarList() #5 {main} thrown in /home/public_html/cal_test/google-api-php/src/Google/Auth/OAuth2.php on line 341The code i'm using is <?php error_reporting(-1); ini_set('display_errors', 'On'); require_once "google-api-php/src/Google/Client.php"; require_once "google-api-php/src/Google/Service/Calendar.php"; // Service Account info $client_id = 'CLIENT_ID'; $service_account_name = 'EMAIL'; $key_file_location = 'FILE_LOC'; // Calendar id $calName = 'CAL_ID'; $client = new Google_Client(); $client->setApplicationName("Calendar test"); $service = new Google_Service_Calendar($client); $key = file_get_contents($key_file_location); $cred = new Google_Auth_AssertionCredentials( $service_account_name, array('https://www.googleapis.com/auth/calendar.readonly'), $key ); $client->setAssertionCredentials($cred); $cals = $service->calendarList->listCalendarList(); //print_r($cals); //exit; $events = $service->events->listEvents($calName); foreach ($events->getItems() as $event) { echo $event->getSummary(); } ?>i've spent serveral hours trying to locate a fix on Google, but so far i'm stuggling Can anyone help me? Thanks Edited by dweb, 09 October 2014 - 06:58 AM. My wife is a Type 1 diabetic and I am trying to put a site together where she can record her blood/glucose readings and analyse the readings.
I am trying to use Google Charts to create a line graph so that she can see if their is a trend during the day when her blood sugar levels peak and trough. But my coding isn't providing any results.
Can anyone see what I am doing wrong?
<?php $level=DB::getInstance()->query("SELECT * FROM tabbyhealth WHERE reading!=0"); foreach ($level->results() as $levelresults) $glucose = $levelresults->reading; $timestamp = date('d M Y h.i A',strtotime($levelresults->timestamp) +18000); ?> <head> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load('visualization', '1.0', {'packages':['corechart']}); google.setOnLoadCallback(drawChart); function drawChart() { var data = new google.visualization.DataTable(); data.addColumn('string', 'Time of Reading'); data.addColumn('number', 'Blood Glucose Reading'); data.addRows([ ['<?php echo $timestamp; ?>', '<?php echo $glucose; ?>'] ]); var options = { title:'Blood Glucose Monitoring', curveType: 'function', legend: { position: 'bottom' } width:600, height:300 hAxis: { title: 'Date/Time' }, vAxis: { title: 'Reading' } }; var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); } </script> </head> <body> <div id="chart_div"></div> </body>I have even tried replacing data.addRows([ ['<?php echo $timestamp; ?>', '<?php echo $glucose; ?>'] ]);with data.addRows([ [0, 0, 0], [1, 10, 5], [2, 23, 15], [3, 17, 9], [4, 18, 10], [5, 9, 5], [6, 11, 3], [7, 27, 19], [8, 33, 25] ]);to see if it is just a problem with reading from my database, but I am still getting nothing - by nothing I mean that no chart is appearing. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=344076.0 I developed a web app using PHP, Mysql. Now I want to give login access for Gmail id's which are already existed in my database, so I used login with Google API, but want to deny login access for any other gmails which do not exist in my database.? So how can i do this?? currently iam using Google+ API For Login With Google & it is giving login access to everyone. Edited September 11, 2019 by cyberRobot Removed image Hi all i was wondering if someone with exp in youtube api could help me out with this I have a website where i want to let people subscribe to others and first off i auth the user Code: [Select] session_start(); set_include_path('path'); require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path Zend_Loader::loadClass('Zend_Gdata_YouTube'); $yt = new Zend_Gdata_YouTube(); Zend_Loader::loadClass('Zend_Gdata_AuthSub'); function getAuthSubRequestUrl() { $next = 'my site'; $scope = 'http://gdata.youtube.com'; $secure = false; $session = true; return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session); } function getAuthSubHttpClient() { if (!isset($_SESSION['sessionToken']) && !isset($_GET['token']) ){ echo '<a href="' . getAuthSubRequestUrl() . '">Login!</a>'; return; } else if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) { $_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']); } $httpClient = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']); return $httpClient; } And that takes me to the page to auth my account, then when i go back to my website and hit the sub button that i made Code: [Select] <?php $username = $_SESSION['username']; include("connect.php"); $mysql = mysql_query("SELECT * FROM users WHERE username = '$username'"); while($row = mysql_fetch_assoc($mysql)){ ?> <table> <tr><td> <?php echo $row['channel']; ?> </td></tr> <tr><td> <form action="sub4sub.php?id=<?php echo $row['id']; ?>" method="POST"> <input type="submit" name="i" value="Sub"> </form> </td></tr></table> <?php } if (isset($_POST['i'])){ $id = $_GET['id']; $sql = mysql_query("SELECT * FROM users WHERE id= $id"); $row = mysql_fetch_assoc($sql); $ytkb = $row['channel']; // this example assumes that $yt is a fully authenticated service object getAuthSubHttpClient(); $subscriptionsFeedUrl = "http://gdata.youtube.com/feeds/api/users/default/subscriptions"; $newSubscription = $yt->newSubscriptionEntry(); $channel = $ytkb; $newSubscription->setUsername(new Zend_Gdata_YouTube_Extension_Username($channel)); // post $yt->insertEntry($newSubscription, $subscriptionsFeedUrl); } ?> So should be subscribing to the persons channel that is displayed in the table, but i get this errors Quote Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 401 <HTML> <HEAD> <TITLE>User authentication required.</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> <H1>User authentication required.</H1> <H2>Error 401</H2> </BODY> </HTML> ' in /home/u292976682/public_html/Zend/library/Zend/Gdata/App.php:709 Stack trace: #0 /home/u292976682/public_html/Zend/library/Zend/Gdata.php(221): Zend_Gdata_App->performHttpRequest('POST', 'http://gdata.yo...', Array, '<atom:entry xml...', 'application/ato...', NULL) #1 /home/u292976682/public_html/Zend/library/Zend/Gdata/App.php(900): Zend_Gdata->performHttpRequest('POST', 'http://gdata.yo...', Array, '<atom:entry xml...', 'application/ato...') #2 /home/u292976682/public_html/Zend/library/Zend/Gdata/App.php(975): Zend_Gdata_App->post(Object(Zend_Gdata_YouTube_SubscriptionEntry), 'http://gdata.yo...', NULL, NULL, Array) #3 /home/u292976682/public_html/sub4sub.php(123): Zend_Gdata_App->insertEntry(Object(Zend_Gdata_YouTube_Subscrip in /home/u292976682/public_html/Zend/library/Zend/Gdata/App.php on line 709 Any help would be great thanks Hi I have been working on this code for almost two weeks and can't get over the last hurdle. If someone can put a fresh set of eys on it I would appreciate it. I have 3 files - a geocoder php script which I can't get to work, but it is exactly like the example given on Google except that I have my addresses broken down by street, city, state and zip. - marker.php which is echoing the data correctly, and my map - location.html which pulls up a map but no markers. my geocoder script is below: Code: [Select] <?php define("MAPS_HOST", "maps.google.com"); define("KEY", "mykey"); // Opens a connection to a MySQL server $connection = mysql_connect("server", "user","pwd"); if (!$connection) { die("Not connected : " . mysql_error()); } // Set the active MySQL database $db_selected = mysql_select_db("Db", $connection); if (!$db_selected) { die("Can\'t use db : " . mysql_error()); } // Select all the rows in the markers table $query = "SELECT * FROM table WHERE 1"; $result = mysql_query($query); if (!$result) { die("Invalid query: " . mysql_error()); } // Initialize delay in geocode speed $delay = 0; $base_url = "http://" . MAPS_HOST . "/maps/geo?output=xml" . "&key=" . KEY; // Iterate through the rows, geocoding each address while ($row = @mysql_fetch_assoc($result)) { $geocode_pending = true; while ($geocode_pending) { $street = $row["street"]; $city = $row["city"]; $state = $row["state"]; $zip_code = $row["zip_code"]; $id = $row["id"]; $request_url = $base_url . "&q=" . urlencode($street + $city + $state + $zip_code); $xml = simplexml_load_file($request_url) or die("url not loading"); $status = $xml->Response->Status->code; if (strcmp($status, "200") == 0) { // Successful geocode $geocode_pending = false; $coordinates = $xml->Response->Placemark->Point->coordinates; $coordinatesSplit = split(",", $coordinates); // Format: Longitude, Latitude, Altitude $lat = $coordinatesSplit[1]; $lng = $coordinatesSplit[0]; $query = sprintf("UPDATE table " . " SET lat = '%s', lng = '%s' " . " WHERE id = '%s' LIMIT 1;", mysql_real_escape_string($lat), mysql_real_escape_string($lng), mysql_real_escape_string($id)); $update_result = mysql_query($query); if (!$update_result) { die("Invalid query: " . mysql_error()); } } else if (strcmp($status, "620") == 0) { // sent geocodes too fast $delay += 100000; } else { // failure to geocode $geocode_pending = false; echo "Address " . $street . " failed to geocoded. "; echo "Received status " . $status . " \n"; } usleep($delay); } } ?> my html file looks like the following: Code: [Select] <!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>location</title> <script src="http://maps.google.com/maps?file=api&v=2&key=mykey" type="text/javascript"></script> <script type="text/javascript"> var iconFlag = new GIcon(); iconFlag.image = 'images/redflag.png'; iconFlag.iconSize = new GSize(12, 20); iconFlag.iconAnchor = new GPoint(6, 20); iconFlag.infoWindowAnchor = new GPoint(5, 1); var iconBlue = new GIcon(); iconBlue.image = 'images/glossy-ball.png'; iconBlue.iconSize = new GSize(12, 20); iconBlue.iconAnchor = new GPoint(6, 20); iconBlue.infoWindowAnchor = new GPoint(5, 1); var iconRed = new GIcon(); iconRed.image = 'images/redbutton.png'; iconRed.iconSize = new GSize(12, 20); iconRed.iconAnchor = new GPoint(6, 20); iconRed.infoWindowAnchor = new GPoint(5, 1); var customIcons = []; customIcons["Db1"] = iconFlag; customIcons["Db2"] = iconBlue; customIcons["Db3"] = iconRed; function load() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(39.0000, 72.0000), 11); // Change this depending on the name of your PHP file GDownloadUrl("marker.php", function(data) { var xml = GXml.parse(data); var markers = xml.documentElement.getElementsByTagName("markers"); for (var i = 0; i < markers.length; i++) { var informant = markers[i].getAttribute("id"); var firstname = markers[i].getAttribute("firstname"); var lastname = markers[i].getAttribute("lastname"); var phone = markers[i].getAttribute("phone"); var zip_code = markers[i].getAttribute("zip_code"); var type = markers[i].getAttribute("type"); var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng"))); var marker = createMarker(point, id, firstname, lastname, street, city, state, zip_code, type); map.addOverlay(marker); } }); } } function createMarker(point, id, firstname, lastname, street, city, state, zip_code, type) { var marker = new GMarker(point, customIcons[type]); var html = "<b>" + id + "</b> <br/>" + firstname + "<br/>" + lastname + "<br/>" + phone + "<br/>" + street + "<br/>" + city + "<br/>" + state + "<br/>" + zip_code +"<br/>" + type; GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(html); }); return marker; } //]]> </script> </head> <body background="images/bg2.jpg"> <body onload="load()" onunload="GUnload()"> <center><div id="map" style="width: 800px; height: 600px"></div></center> </body> </html> Thanks for any help |