Search Results

Search found 70 results on 3 pages for 'gevent'.

Page 3/3 | < Previous Page | 1 2 3 

  • Google Maps: openInfoWindowTabsHtml + GDownloadUrl (Ajax call) question

    - by Spiros
    I am facing the following problem. On an Google Map I want to add info windows with tabs, where content is loaded from an external file using the GDownloadUrl method. The code works about fine, but with two problems. a) The first time I click on a marker, nothing hapens. I need to click twice to get an info box. After that it works ok. b) When I close an info box and open it again, the tabs repeat themselves. Every time I reopen the info box, those tabs get repeated. So, if using the code below and open the info box 3 times, I get 6 tabs (Info, Photos, Info, Photos, Info, Photos). Any idea of what I am doing wrong here? I have also tried this with JQuery's $.get method, but the results are exactly the same. function createREMarker(lat,long,reID) { var reMarker = new GMarker(rePoint,iconRE); GEvent.addListener(reMarker, "click", function() { GDownloadUrl('testcontent.php?reID='+reID+'&what=info', function(data) { content1 = data; }); GDownloadUrl('testcontent.php?reID='+reID+'&what=photos', function(data) { content2 = data; }); tabs.push(new GInfoWindowTab('Info', '<div id="mapOverlayContent" style="width:375px; height:220px; overflow:auto;">'+content1+'</div>')); tabs.push(new GInfoWindowTab('Photos', '<div id="mapOverlayContent" style="width:375px; height:220px; overflow:auto;">'+content2+'</div>')); reMarker.openInfoWindowTabsHtml(tabs); }); return reMarker; };

    Read the article

  • Google Maps openInfoWindowHTML array problem

    - by user188791
    Could someone please help explain why I can't get this to work? I properly generates all the locations, however, it doesn't generate the info boxes. Why is this and can someone help me with it? var map = new GMap2(document.getElementById("map")); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(47.6062, -122.3321), 8); var wa_locations = new Array(new Array("Seattle", "47.6062", "-122.3321", "###-###-####", "###-###-####"), new Array("Bellevue", "47.6104", "-122.2007", "###-###-####", "###-###-####"), new Array("Tacoma", "47.2529", "-122.4443", "###-###-####", "###-###-####"), new Array("Everett", "47.9790", "-122.2021", "###-###-####", "###-###-####")); for(var i = 0; i < wa_locations.length; i++) { var point = new GLatLng(wa_locations[i][1], wa_locations[i][2]); map.addOverlay(new GMarker(point)); GEvent.addListener(point, "click", function() { point.openInfoWindowHtml("<b>" + wa_locations[i][0] + "</b><br/>Sales: " + wa_locations[i][3] + "<br/>Helpdesk: " + wa_locations[i][4] + ""); }); }

    Read the article

  • Google Maps, marker info window won't show up ?

    - by user296516
    Hi guys, I have written this code that loops through an array of lat/long coordinates and places a marker at each of the coordinate. Everything forks fine, exempt the info window won't appear once the marker is clicked. var ExpTowerIcon = new GIcon(); ExpTowerIcon.image = "tower.png"; ExpTowerIcon.iconSize = new GSize(75, 75); ExpTowerIcon.iconAnchor = new GPoint(37, 65); ExpTowerIcon.infoWindowAnchor = new GPoint(37, 20); var marker=new Array(); for ( i=0 ; i < lat.length ; i++ ) { var MarkerPoint = new GLatLng(lat[i],long[i]); marker[i] = new GMarker(MarkerPoint,{icon:ExpTowerIcon}) map.addOverlay( marker[i] ); GEvent.addListener( marker[i] , 'click', function() { marker[i].openInfoWindowHtml('Hello!') ; }); var polyline = new GPolyline([ new GLatLng(lat[i],long[i]) , new GLatLng(lat[i+1],long[i+1]) ], "#ff0000", 5); map.addOverlay(polyline); } Any ideas? Thanks!

    Read the article

  • Google Maps inside custom PODS page

    - by Sharath
    I have a custom pods page called addstory.php which uses a public form to display some input fields. For one of the fields, i have a input helper that displays a google map location which I can use to pick out a location which is stored in comma separated variable. Here is the input helper code... <div class="form pick <?php echo $location; ?>"> <div id="map" style="width:500; height:500"> </div> <script type="text/javascript"> $(function() { map=new GMap(document.getElementById("map")); map.centerAndZoom(new GPoint(77.595062,13.043359),6); map.setUIToDefault(); GEvent.addListener(map,"click",function(overlay,latlng) { map.clearOverlays(); var marker = new GMarker(latlng); map.addOverlay(marker); //Extra stuff here.. } ); }); </script> </div> And this is the code inside my addstory.php <?php get_header(); $rw = new Pod('rainwater'); $fields=array( 'name', 'email', 'location'=>array('input_helper'=>'gmap_location'), ); echo $rw->publicForm($fields); ?> I get the following error...and the google map doesn't load. a is null error source line: [Break on this error] function Qd(a){for(var b;b=a.firstChild;){Rg(b);a.removeChild(b)}}

    Read the article

  • Getting exception when trying to monkey patch pymongo.connection._Pool

    - by Creotiv
    I use pymongo 1.9 on Ubuntu 10.10 with python 2.6.6 When i trying to monkey patch pymongo.connection._Pool i'm getting error on connection: AutoReconnect: could not find master/primary But when i change _Pool class in pymongo.connection module, it work pretty fine. Even if i copy _Pool implementation from pymongo.connection module and will try to monkey patch by the same code, it still giving same exception. I need to remove threading.local from _Pool class, because i use gevent and i need to implement Pool for all mongo connections(for all threads). I use this code: import pymongo class GPool: """A simple connection pool. Uses thread-local socket per thread. By calling return_socket() a thread can return a socket to the pool. Right now the pool size is capped at 10 sockets - we can expose this as a parameter later, if needed. """ # Non thread-locals __slots__ = ["sockets", "socket_factory", "pool_size","sock"] #sock = None def __init__(self, socket_factory): self.pool_size = 10 if not hasattr(self,"sock"): self.sock = None self.socket_factory = socket_factory if not hasattr(self, "sockets"): self.sockets = [] def socket(self): # we store the pid here to avoid issues with fork / # multiprocessing - see # test.test_connection:TestConnection.test_fork for an example # of what could go wrong otherwise pid = os.getpid() if self.sock is not None and self.sock[0] == pid: return self.sock[1] try: self.sock = (pid, self.sockets.pop()) except IndexError: self.sock = (pid, self.socket_factory()) return self.sock[1] def return_socket(self): if self.sock is not None and self.sock[0] == os.getpid(): # There's a race condition here, but we deliberately # ignore it. It means that if the pool_size is 10 we # might actually keep slightly more than that. if len(self.sockets) < self.pool_size: self.sockets.append(self.sock[1]) else: self.sock[1].close() self.sock = None pymongo.connection._Pool = GPool

    Read the article

  • Clicking inside a polygon in Google Maps

    - by amarsh-anand
    The included JavaScript snippet is supposed to do the following: As the user clicks on the map, initialize headMarker and draw a circle (polygon) around it As the user clicks inside the circle, initialize tailMarker and draw the path between these two markers 1 is happening as expected. But as the user clicks inside the circle, in the function(overlay,point), overlay is non-null while point is null. Because of this, the code fails to initialize tailMarker. Can someone tell me a way out. GEvent.addListener(map, "click", function(overlay,point) { if (isCreateHeadPoint) { // add the head marker headMarker = new GMarker(point,{icon:redIcon,title:'0'}); map.addOverlay(headMarker); isCreateHeadPoint = false; // draw the circle drawMapCircle(point.lat(),point.lng(),1,'#cc0000',2,0.8,'#0',0.1); } else { // add the tail marker tailMarker = new GMarker(point,{icon:greenIcon,title:''}); map.addOverlay(tailMarker); isCreateHeadPoint = true; // load thes path from head to tail direction.load("from:" + headMarker.getPoint().lat()+ ", " + headMarker.getPoint().lng()+ " " + "to:" + tailMarker.getPoint().lat() + "," + tailMarker.getPoint().lng(), {getPolyline:true}); } });

    Read the article

  • google maps call within a For Loop not returning distance

    - by Richard Reddy
    Hi, I am calling google maps within a for loop in my javascript as I have mulitple routes that need to be costed separately based on distances. Everything works great except that the distance is only returned for one of the routes. I have a feeling that it is something to do with the way I have the items declared within the ajax call for the maps. Any ideas what could be the issue from the code below? for (var i = 1; i <= numJourneys; i++) { var mapContainer = 'directionsMap' + i; var directionContainer = $('#getDistance' + i); $.ajax({ async: false, type: "POST", url: "Journey/LoadWayPoints", data: "{'args': '" + i + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { if (msg.d != '[]') { var map = new GMap2(document.getElementById(mapContainer)); var distance = directionContainer; var wp = new Array(); //routes var counter = 0; $.each(content, function () { wp[counter] = new GLatLng(this['Lat'], this['Long']); counter = counter + 1; }); map.clearOverlays(); map.setCenter(wp[0], 14); // load directions directions = new GDirections(map); GEvent.addListener(directions, "load", function () { alert(directions.getDistance()); //directionContainer.html(directions.getDistance().html); }); directions.loadFromWaypoints(wp, { getSteps: true }); } } }); }

    Read the article

  • Multiple marker icons, how to add to google mashup

    - by user351189
    I have created a Google maps mashup, where with a bit of input, I have managed to have a sidebar that links to a video icon/marker that then opens up an info window showing virtual tours. I would, however, like to put different coloured marker icons on the map depending on the category that the video is in. This would be easy enough to do, but my page is made up of a mixture of J-Query and JavaScript all calling to the individual flash files. Could someone help me with the code for adding extra marker icons for different categories? Here is the code: So, after the intial 'var camera;' point, there comes this: function addMarker(point, title, video, details) { var marker = new GMarker(point, {title: title, icon:camera}); GEvent.addListener(marker, "click", function() { if (details) { marker.openInfoWindowTabsHtml([new GInfoWindowTab("Video", video), new GInfoWindowTab("More", details)]); } else { marker.openInfoWindowHtml(video); } }); Then further down, is the code for calling the individual marker image. I would like to add another image to this list - would I start out by calling the new object 'camera-red.image' or something similar? function initialize() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("mapDiv")); map.setCenter(new GLatLng(51.52484592590448, -0.13345599174499512), 17); map.setUIToDefault(); var uclvtSatMapType = createUclVTSatMapType() map.addMapType(uclvtSatMapType); map.setMapType(uclvtSatMapType); camera = new GIcon(G_DEFAULT_ICON); camera.image = "ucl-video.png"; camera.iconSize = new GSize(32,37); camera.iconAnchor = new GPoint(16,35); camera.infoWindowAnchor = new GPoint(16,2); addMarkersToMap(); } The actual map can be found here: link text Thanks.

    Read the article

  • Google maps and J-Query: Individual markers?

    - by user351189
    Hi there, I have created a Google maps mashup, where with a bit of input, I have managed to have a sidebar that links to a video icon/marker that then opens up an info window showing virtual tours. I would, however, like to put different coloured marker icons on the map depending on the category that the video is in. This would be easy enough to do, but my page is made up of a mixture of J-Query and JavaScript all calling to the individual flash files. Could someone help me with the code for adding extra marker icons for different categories? Here is the code: So, after the intial 'var camera;' point, there comes this: function addMarker(point, title, video, details) { var marker = new GMarker(point, {title: title, icon:camera}); GEvent.addListener(marker, "click", function() { if (details) { marker.openInfoWindowTabsHtml([new GInfoWindowTab("Video", video), new GInfoWindowTab("More", details)]); } else { marker.openInfoWindowHtml(video); } }); Then further down, is the code for calling the individual marker image. I would like to add another image to this list - would I start out by calling the new object 'camera-red.image' or something similar? function initialize() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("mapDiv")); map.setCenter(new GLatLng(51.52484592590448, -0.13345599174499512), 17); map.setUIToDefault(); var uclvtSatMapType = createUclVTSatMapType() map.addMapType(uclvtSatMapType); map.setMapType(uclvtSatMapType); camera = new GIcon(G_DEFAULT_ICON); camera.image = "ucl-video.png"; camera.iconSize = new GSize(32,37); camera.iconAnchor = new GPoint(16,35); camera.infoWindowAnchor = new GPoint(16,2); addMarkersToMap(); } The actual map can be found here: link text Thanks. Gray

    Read the article

  • Returning JSON from JavaScript to Python

    - by Chris Lacy
    I'm writing a simple App Engine app. I have a simple page that allows a user to move a marker on a Google map instance. Each time the user drops the marker, I want to return the long/lat to my Python app. function initialize() { ... // Init map var marker = new GMarker(center, {draggable: true}); GEvent.addListener(marker, "dragend", function() { // I want to return the marker.x/y to my app when this function is called .. }); } To my (admittedly limited) knowledge, I should be: 1). Returning a JSON structure with my required data in the listener callback above 2). In my webapp.RequestHandler Handler class, trying to retrieve the JSON structure during the post method. I would very much like to pass this JSOn data back to the app without causing a page reload (which is what has happened when I've used various post/form.submit methods so far). Can anyone provide me with some psuedo code or an example on how I might achieve what I'm after? Thanks.

    Read the article

  • Using JSON Data to Populate a Google Map with Database Objects

    - by MikeH
    I'm revising this question after reading the resources mentioned in the original answers and working through implementing it. I'm using the google maps api to integrate a map into my Rails site. I have a markets model with the following columns: ID, name, address, lat, lng. On my markets/index view, I want to populate a map with all the markets in my markets table. I'm trying to output @markets as json data, and that's where I'm running into problems. I have the basic map displaying, but right now it's just a blank map. I'm following the tutorials very closely, but I can't get the markers to generate dynamically from the json. Any help is much appreciated! Here's my setup: Markets Controller: def index @markets = Market.filter_city(params[:filter]) respond_to do |format| format.html # index.html.erb format.json { render :json => @market} format.xml { render :xml => @market } end end Markets/index view: <head> <script type="text/javascript" src="http://www.google.com/jsapi?key=GOOGLE KEY REDACTED, BUT IT'S THERE" > </script> <script type="text/javascript"> var markets = <%= @markets.to_json %>; </script> <script type="text/javascript" charset="utf-8"> google.load("maps", "2.x"); google.load("jquery", "1.3.2"); </script> </head> <body> <div id="map" style="width:400px; height:300px;"></div> </body> Public/javascripts/application.js: function initialize() { if (GBrowserIsCompatible() && typeof markets != 'undefined') { var map = new GMap2(document.getElementById("map")); map.setCenter(new GLatLng(40.7371, -73.9903), 13); map.addControl(new GLargeMapControl()); function createMarker(latlng, market) { var marker = new GMarker(latlng); var html="<strong>"+market.name+"</strong><br />"+market.address; GEvent.addListener(marker,"click", function() { map.openInfoWindowHtml(latlng, html); }); return marker; } var bounds = new GLatLngBounds; for (var i = 0; i < markets.length; i++) { var latlng=new GLatLng(markets[i].lat,markets[i].lng) bounds.extend(latlng); map.addOverlay(createMarker(latlng, markets[i])); } } } window.onload=initialize; window.onunload=GUnload;

    Read the article

  • Rails Google Maps integration Javascript problem

    - by JZ
    I'm working on Rails 3.0.0.beta2, following Advanced Rails Recipes "Recipe #32, Mark locations on a Google Map" and I hit a road block: I do not see a google map. My @adds view uses @adds.to_json to connect the google maps api with my model. My database contains "latitude" "longitude", as floating points. And the entire project can be accessed at github. Can you see where I'm not connecting the to_json output with the javascript correctly? Can you see other glairing errors in my javascript? Thanks in advance! My application.js file: function initialize() { if (GBrowserIsCompatible() && typeof adds != 'undefined') { var map = new GMap2(document.getElementById("map")); map.setCenter(new GLatLng(37.4419, -122.1419), 13); map.addControl(new GLargeMapControl()); function createMarker(latlng, add) { var marker = new GMarker(latlng); var html="<strong>"+add.first_name+"</strong><br />"+add.address; GEvent.addListener(marker,"click", function() { map.openInfoWindowHtml(latlng, html); }); return marker; } var bounds = new GLatLngBounds; for (var i = 0; i < adds.length; i++) { var latlng=new GLatLng(adds[i].latitude,adds[i].longitude) bounds.extend(latlng); map.addOverlay(createMarker(latlng, adds[i])); } map.setCenter(bounds.getCenter(),map.getBoundsZoomLevel(bounds)); } } window.onload=initialize; window.onunload=GUnload; Layouts/adds.html.erb: <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true_or_false&amp;key=ABQIAAAAeH4ThRuftWNHlwYdvcK1QBTJQa0g3IQ9GZqIMmInSLzwtGDKaBQvZChl_y5OHf0juslJRNx7TbxK3Q" type="text/javascript"></script> <% if @adds -%> <script type="text/javascript"> var maps = <%= @adds.to_json %>; </script> <% end -%>

    Read the article

  • how to drag a 'div' element to the google maps ,that be changed to a 'marker'..use jquery

    - by zjm1126
    this is my code : <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"> </head> <body onload="initialize()" onunload="GUnload()"> <style type="text/css"> </style> <div id="map_canvas" style="width: 500px; height: 300px;float:left;"></div> <div id=b style="width: 50px; height: 50px;background:red;float:left;margin-left:300px;"></div> <script src="jquery-1.4.2.js" type="text/javascript"></script> <script src="jquery-ui-1.8rc3.custom.min.js" type="text/javascript"></script> <script src="http://ditu.google.cn/maps?file=api&amp;v=2&amp;key=ABQIAAAA-7cuV3vqp7w6zUNiN_F4uBRi_j0U6kJrkFvY4-OX2XYmEAa76BSNz0ifabgugotzJgrxyodPDmheRA&sensor=false"type="text/javascript"></script> <script type="text/javascript"> //********** function initialize() { if (GBrowserIsCompatible()) { // function createMarker(point, number) { var marker = new GMarker(point); var message = ["?","?","?","??","??"]; marker.value = number; GEvent.addListener(marker, "click", function() { var myHtml = "<b>#" + number + "</b><br/>" + message[number -1]; map.openInfoWindowHtml(point, myHtml); }); return marker; } // var map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(39.9493, 116.3975), 13); // Add 5 markers to the map at random locations var bounds = map.getBounds(); var southWest = bounds.getSouthWest(); var northEast = bounds.getNorthEast(); var lngSpan = northEast.lng() - southWest.lng(); var latSpan = northEast.lat() - southWest.lat(); for (var i = 0; i < 5; i++) { var point = new GLatLng(southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random()); map.addOverlay(createMarker(point, i + 1)); } } } //************* $("#b").draggable(); </script> </body> </html>

    Read the article

  • how to set a polyline on google maps every time when i click twice(make two markers) on maps,

    - by zjm1126
    this is my code : thanks <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=5.0,user-scalable=yes"> </head> <body onload="initialize()" onunload="GUnload()"> <style type="text/css"> </style> <div id="map_canvas" style="width: 500px; height: 300px;float:left;"></div> <script src="jquery-1.4.2.js" type="text/javascript"></script> <script src="jquery-ui-1.8rc3.custom.min.js" type="text/javascript"></script> <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA-7cuV3vqp7w6zUNiN_F4uBRi_j0U6kJrkFvY4-OX2XYmEAa76BSNz0ifabgugotzJgrxyodPDmheRA&sensor=false"type="text/javascript"></script> <script type="text/javascript"> //********** function initialize() { if (GBrowserIsCompatible()){ //var map = new GMap2(document.getElementById("map_canvas")); //map.setCenter(new GLatLng(39.9493, 116.3975), 13); var map = new GMap2(document.getElementById("map_canvas")); var center=new GLatLng(39.917,116.397); map.setCenter(center, 13); map.addOverlay(new GMarker(new GLatLng(39.917,116.397))); map.enableDrawing() //GEvent.addListener(map, "mouseover", function() { //alert("???????"); //}); var one; aFn=function(y_scale,x_scale){ //************ //function p(){ var bounds = map.getBounds(); var southWest = bounds.getSouthWest(); var northEast = bounds.getNorthEast(); var lngSpan = northEast.lng() - southWest.lng(); var latSpan = northEast.lat() - southWest.lat(); var point = new GLatLng(southWest.lat() + latSpan * (1-y_scale), southWest.lng() + lngSpan * x_scale); if(!one){ map.addOverlay(new GMarker(point)); one=point; }else{ var polyline = new GPolyline([one,point], "#ff0000", 5); map.addOverlay(polyline); one=0; } } //********** //************* } } </script> </body> </html>

    Read the article

  • Google Maps rendering locally but not in live environment

    - by marcusstarnes
    I have a page that renders a simple google map for a specified location. This map renders without any problems at all when I run it locally on localhost, however, when I deploy this code to our live web servers (using our LIVE google API key for the appropriate domain) it fails to render, and upon putting a series of alerts within the javascript on the page, it appears that the 'Initialize' method (which should be called within body onLoad) is not being called. When I view the HTML source that is rendered on the live server it appears exactly as per the local version of the site (including the call to initialize() within the body onLoad event), albeit with the different maps API key. I have output the host (alert(window.location.host);) to ensure that the key I generated via the google maps api site, corresponds exactly to the live server, which it does. Does anyone have any ideas why it would be working locally but not when deployed to the live servers? The live site is hosted on 2 load-balanced web servers. This is the javascript that is rendered: <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAA-BU8POZj19wRlTaKIXVM9xTz76xxk4yAELG9u79oXrhnLTB5NRRvAZ-bkKn1x8J68nfRTVOIWNPJEA" type="text/javascript"></script> <script type="text/javascript"> var map; var geocoder; alert(window.location.host); function initialize() { if (GBrowserIsCompatible()) { map = new GMap2(document.getElementById("businessMap")); map.setUIToDefault(); geocoder = new GClientGeocoder(); showAddress('St Margarets Street SW1P 3 London'); } } function showAddress(address) { geocoder.getLatLng( address, function(point) { if (!point) { // Address could not be located. jQuery('#googleMap').hide(); } else { map.setCenter(point, 13); var marker = new GMarker(point); map.addOverlay(marker); var html = 'Address info for the marker'; marker.openInfoWindow(html); GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); }); } } ); } </script> Any help would be much appreciated. Thanks.

    Read the article

  • Google maps sometimes does not return a geocoded value for string

    - by XGreen
    Hi Guys, I have the following code: It basically looks into a HTML list and geocodes and markets each item. it does it correctly 8 out of ten but sometimes I get an error I set for show in the console. I can't think of anything. Any thoughts is much appreciated. $(function () { var map = null; var geocoder = null; function initialize() { if (GBrowserIsCompatible()) { // Specifies that the element with the ID map is the container for the map map = new GMap2(document.getElementById("map")); // Sets an initial map positon (which mainly gets ignored after reading the adderesses list) map.setCenter(new GLatLng(37.4419, -122.1419), 13); // Instatiates the google Geocoder class geocoder = new GClientGeocoder(); map.addControl(new GSmallMapControl()); // Sets map zooming controls on the map map.enableScrollWheelZoom(); // Allows the mouse wheel to control the map while on it } } function showAddress(address, linkHTML) { if (geocoder) { geocoder.getLatLng(address, function (point) { if (!point) { console.log('Geocoder did not return a location for ' + address); } else { map.setCenter(point, 8); var marker = new GMarker(point); map.addOverlay(marker); // Assigns the click event to each marker to open its balloon GEvent.addListener(marker, "click", function () { marker.openInfoWindowHtml(linkHTML); }); } } ); } } // end of show address function initialize(); // This iterates through the text of each address and tells the map // to show its location on the map. An internal error is thrown if // the location is not found. $.each($('.addresses li a'), function () { var addressAnchor = $(this); showAddress(addressAnchor.text(), $(this).parent().html()); }); }); which looks into this HTML: <ul class="addresses"> <li><a href="#">Central London</a></li> <li><a href="#">London WC1</a></li> <li><a href="#">London Shoreditch</a></li> <li><a href="#">London EC1</a></li> <li><a href="#">London EC2</a></li> <li><a href="#">London EC3</a></li> <li><a href="#">London EC4</a></li> </ul>

    Read the article

  • Using JSON Data to Populate a Google Map with Database Objects

    - by MikeH
    I'm revising this question after reading the resources mentioned in the original answers and working through implementing it. I'm using the google maps api to integrate a map into my Rails site. I have a markets model with the following columns: ID, name, address, lat, lng. On my markets/index view, I want to populate a map with all the markets in my markets table. I'm trying to output @markets as json data, and that's where I'm running into problems. I have the basic map displaying, but right now it's just a blank map. I'm following the tutorials very closely, but I can't get the markers to generate dynamically from the json. Any help is much appreciated! Here's my setup: Markets Controller: def index @markets = Market.filter_city(params[:filter]) respond_to do |format| format.html # index.html.erb format.json { render :json => @market} format.xml { render :xml => @market } end end Markets/index view: <head> <script type="text/javascript" src="http://www.google.com/jsapi?key=GOOGLE KEY REDACTED, BUT IT'S THERE" > </script> <script type="text/javascript"> var markets = <%= @markets.to_json %>; </script> <script type="text/javascript" charset="utf-8"> google.load("maps", "2.x"); google.load("jquery", "1.3.2"); </script> </head> <body> <div id="map" style="width:400px; height:300px;"></div> </body> Public/javascripts/application.js: function initialize() { if (GBrowserIsCompatible() && typeof markets != 'undefined') { var map = new GMap2(document.getElementById("map")); map.setCenter(new GLatLng(40.7371, -73.9903), 13); map.addControl(new GLargeMapControl()); function createMarker(latlng, market) { var marker = new GMarker(latlng); var html="<strong>"+market.name+"</strong><br />"+market.address; GEvent.addListener(marker,"click", function() { map.openInfoWindowHtml(latlng, html); }); return marker; } var bounds = new GLatLngBounds; for (var i = 0; i < markets.length; i++) { var latlng=new GLatLng(markets[i].lat,markets[i].lng) bounds.extend(latlng); map.addOverlay(createMarker(latlng, markets[i])); } } } window.onload=initialize; window.onunload=GUnload;

    Read the article

  • Which code snipplets in PHP can create a input form, which creates a new set of data in my mysql dat

    - by smiyazaki
    I am using the Google Maps API with parts in javascript and others in PHP. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Google Maps AJAX + mySQL/PHP Example // var iconBlue = new GIcon(); iconBlue.image = 'icon.png'; iconBlue.shadow = ''; iconBlue.iconSize = new GSize(19, 19); iconBlue.shadowSize = new GSize(22, 20); iconBlue.iconAnchor = new GPoint(6, 20); iconBlue.infoWindowAnchor = new GPoint(5, 1); var iconRed = new GIcon(); iconRed.image = 'icon.png'; iconRed.shadow = ''; iconRed.iconSize = new GSize(19, 19); 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.setMapType(G_SATELLITE_MAP); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(47.614495, -122.341861), 13); // Change this depending on the name of your PHP file GDownloadUrl("phpsqlajax_genxml.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; } //]]> (I suppose the php will be called by "GDownloadUrl("phpsqlajax_genxml.php", function(data) { ..." in the javascript part of the sourcecode of phpsqlajax_map.htm) Now I need another php file and the code snipplets for it, which creates an input form where I can add some new locations to the google map. Following code is used to create the xml file here: http://detektors.de/maptest/phpsqlajax_genxml.php The next step would be, trying to make an plugin for wordpress that I could easily post a blog entry with a new location on the same map, which displays already some other locations stored in the mysql database. thanks! <?php require("phpsqlajax_dbinfo.php"); function parseToXML($htmlStr) { $xmlStr=str_replace('<','<',$htmlStr); $xmlStr=str_replace('','>',$xmlStr); $xmlStr=str_replace('"','"',$xmlStr); $xmlStr=str_replace("'",''',$xmlStr); $xmlStr=str_replace("&",'&',$xmlStr); return $xmlStr; } // Opens a connection to a MySQL server $connection=mysql_connect ($host, $username, $password); if (!$connection) { die('Not connected : ' . mysql_error()); } // Set the active MySQL database $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die ('Can\'t use db : ' . mysql_error()); } // Select all the rows in the markers table $query = "SELECT * FROM markers WHERE 1"; $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()); } header("Content-type: text/xml"); // Start XML file, echo parent node echo ''; // Iterate through the rows, printing XML nodes for each while ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE echo ''; } // End XML file echo ''; ?

    Read the article

  • What sort of loop structure to compare checkbox matrix with Google Maps markers?

    - by Kirkman14
    I'm trying to build a map of trails around my town. I'm using an XML file to hold all the trail data. For each marker, I have categories like "surface," "difficulty," "uses," etc. I have seen many examples of Google Maps that use checkboxes to show markers by category. However these examples are usually very simple: maybe three different checkboxes. What's different on my end is that I have multiple categories, and within each category there are several possible values. So, a particular trail might have "use" values of "hiking," "biking," "jogging," and "equestrian" because all are allowed. I put together one version, which you can see here: http://www.joshrenaud.com/pd/trails_withcheckboxes3.html In this version, any trail that has any value checked by the user will be displayed on the map. This version works. (although I should point out there is a bug where despite only one category being checked on load, all markers display anyway. After your first click on any checkbox, the map will work properly) However I now realize it's not quite what I want. I want to change it so that it will display only markers that match ALL the values that are checked (rather than ANY, which is what the example above does). I took a hack at this. You can see the result online, but I can't type a link to it because I am new user. Change the "3" in the URL above to a "4" to see it. My questions are about this SECOND url. (trails_withcheckboxes4.html) It doesn't work. I am pretty new to Javascript, so I am sure I have done something totally wrong, but I can't figure out what. My specific questions: Does anyone see anything glaringly obvious that is keeping my second example from working? If not, could someone just suggest what sort of loop structure I would need to build to compare the several arrays of checkboxes with the several arrays of values on any given marker? Here is some of the relevant code, although you can just view source on the examples above to see the whole thing: function createMarker(point,surface,difficulty,use,html) { var marker = new GMarker(point,GIcon); marker.mysurface = surface; marker.mydifficulty = difficulty; marker.myuse = use; GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); }); gmarkers.push(marker); return marker; } function show() { hide(); var surfaceChecked = []; var difficultyChecked = []; var useChecked = []; var j=0; // okay, let's run through the checkbox elements and make arrays to serve as holders of any values the user has checked. for (i=0; i<surfaceArray.length; i++) { if (document.getElementById('surface'+surfaceArray[i]).checked == true) { surfaceChecked[j] = surfaceArray[i]; j++; } } j=0; for (i=0; i<difficultyArray.length; i++) { if (document.getElementById('difficulty'+difficultyArray[i]).checked == true) { difficultyChecked[j] = difficultyArray[i]; j++; } } j=0; for (i=0; i<useArray.length; i++) { if (document.getElementById('use'+useArray[i]).checked == true) { useChecked[j] = useArray[i]; j++; } } //now that we have our 'xxxChecked' holders, it's time to go through all the markers and see which to show. for (var k=0; k<gmarkers.length; k++) { // this loop runs thru all markers var surfaceMatches = []; var difficultyMatches = []; var useMatches = []; var surfaceOK = false; var difficultyOK = false; var useOK = false; for (var l=0; l<surfaceChecked.length; l++) { // this loops runs through all checked Surface categories for (var m=0; m<gmarkers[k].mysurface.length; m++) { // this loops through all surfaces on the marker if (gmarkers[k].mysurface[m].childNodes[0].nodeValue == surfaceChecked[l]) { surfaceMatches[l] = true; } } } for (l=0; l<difficultyChecked.length; l++) { // this loops runs through all checked Difficulty categories for (m=0; m<gmarkers[k].mydifficulty.length; m++) { // this loops through all difficulties on the marker if (gmarkers[k].mydifficulty[m].childNodes[0].nodeValue == difficultyChecked[l]) { difficultyMatches[l] = true; } } } for (l=0; l<useChecked.length; l++) { // this loops runs through all checked Use categories for (m=0; m<gmarkers[k].myuse.length; m++) { // this loops through all uses on the marker if (gmarkers[k].myuse[m].childNodes[0].nodeValue == useChecked[l]) { useMatches[l] = true; } } } // now it's time to loop thru the Match arrays and make sure they are all completely true. for (m=0; m<surfaceMatches.length; m++) { if (surfaceMatches[m] == true) { surfaceOK = true; } else if (surfaceMatches[m] == false) {surfaceOK = false; break; } } for (m=0; m<difficultyMatches.length; m++) { if (difficultyMatches[m] == true) { difficultyOK = true; } else if (difficultyMatches[m] == false) {difficultyOK = false; break; } } for (m=0; m<useMatches.length; m++) { if (useMatches[m] == true) { useOK = true; } else if (useMatches[m] == false) {useOK = false; break; } } // And finally, if each of the three OK's is true, then let's show the marker. if ((surfaceOK == true) && (difficultyOK == true) && (useOK == true)) { gmarkers[i].show(); } } }

    Read the article

  • Pass data from one form to another on a seperate page

    - by Micanio
    I am building a price/distance calculator with Google Maps API and am trying to pass the info from the calculator to a booking form on a separate page. My first form has 2 submit buttons - one to make the calculation, and one to submit the relevant data to the booking form. I'm stuck trying to make the 2nd button work. Once the API calculation has been made, I get 4 values - From, To, Cost, Distance. I am trying to pass the From, To and Cost values into my booking form by clicking the second button. But I can;t seem to get it to work. I've tried POST and GET but I think I may have been doing something wrong with both. Any help is appreciated. Code for API form: <script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAwCUxKrPl8_9WadET5dc4KxTqOwVK5HCwTKtW27PjzpqojXnJORQ2kUsdCksByD4hzcGXiOxvn6C4cw&sensor=true"></script> <script type="text/javascript"> var geocoder = null; var location1 = null; var location2 = null; var gDir = null; var directions = null; var total = 0; function roundNumber(num, dec) { var result = Math.floor(num*Math.pow(10 ,dec))/Math.pow(10,dec); return result; } function from(form) { address1=form.start.options[form.start.selectedIndex].value form.address1.value=address1 form.address1.focus() } function to(form) { address2=form.end.options[form.end.selectedIndex].value form.address2.value=address2 form.address2.focus() } function initialize() { var map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(54.019066,-1.381531),9); map.setMapType(G_NORMAL_MAP); geocoder = new GClientGeocoder(); gDir = new GDirections(map); GEvent.addListener(gDir, "load", function() { var drivingDistanceMiles = gDir.getDistance().meters / 1609.344; var drivingDistanceKilometers = gDir.getDistance().meters / 1000; var miles = drivingDistanceMiles.toFixed(0); //var cost = (((miles - 1) * 1.9) + 3.6).toFixed(2); var meters = gDir.getDistance().meters.toFixed(1); if(miles < 70){ var cost = miles *1.75; } if(miles >70){ var cost = miles *1.2; } document.getElementById('from').innerHTML = '<strong>From: </strong>' + location1.address; document.getElementById('to').innerHTML = '<strong>To: </strong>' + location2.address; document.getElementById('cost').innerHTML = '<span class="fare"><strong>Estimated Taxi FARE:</strong>' + ' £' + cost.toFixed(2) + '</span>'; document.getElementById('miles').innerHTML = '<strong>Distance: </strong>' + miles + ' Miles'; }); } function showLocation() // start of possible values for address not recognized on google search // values for address1 { if (document.forms[0].address1.value == "heathrow" || document.forms[0].address1.value == "Heathrow" || document.forms[0].address1.value == "heathrow airport" || document.forms[0].address1.value == "Heathrow Airport" || document.forms[0].address1.value == "London Heathrow" || document.forms[0].address1.value =="london heathrow" ) { (document.forms[0].address1.value = "Heathrow Airport"); } if (document.forms[0].address2.value == "heathrow" || document.forms[0].address2.value == "Heathrow" || document.forms[0].address2.value == "heathrow airport" || document.forms[0].address2.value == "Heathrow Airport" || document.forms[0].address2.value == "London Heathrow" || document.forms[0].address2.value =="london heathrow" ) { (document.forms[0].address2.value = "Heathrow Airport"); } geocoder.getLocations(document.forms[0].address1.value + document.forms[0].uk.value || document.forms[0].start.value + document.forms[0].uk.value, function (response) { if (!response || response.Status.code != 200) { alert("Sorry, we were unable to find the first address"); } else { location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address}; geocoder.getLocations(document.forms[0].address2.value + document.forms[0].uk.value, function (response) { if (!response || response.Status.code != 200) { alert("Sorry, we were unable to find the second address"); } else { location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address}; gDir.load('from: ' + location1.address + ' to: ' + location2.address); } }); } }); } </script> <style> #quote { font-family: Georgia, "Times New Roman", Times, serif; } </style> </head> <body style="background-color: rgb(255, 255, 255);" onUnload="GUnload()" onLoad="initialize()"> <div id="sidebar"> <!--MAPS--> <div id="calc_top"></div> <div id="calc_body"> <div id="calc_inside"> <span style="font-size: 16px; font-weight: bold;">Get A Quote Now</span> <p class="disclaimer">Fares can be calculated using either Area, Exact Address or Postcode, when entering address please include both road name and area i.e. <em>Harrogate Road, Ripon</em>. You can also select a pickup point and destination from the dropdown boxes. </p> <form onSubmit="showLocation(); return false;" action="#" id="booking_form"> <p> <select onChange="from(this.form)" name="start"> <option selected="selected">Select a Pickup Point</option> <option value="Leeds Bradford Airport">Leeds Bradford Airport</option> <option value="Manchester Airport">Manchester Airport</option> <option value="Teesside International Airport">Teeside Airport</option> <option value="Liverpool John Lennon Airport">Liverpool Airport</option> <option value="East Midlands Airport">East Midlands Airport</option> <option value="Heathrow International Airport">Heathrow Airport</option> <option value="Gatwick Airport">Gatwick Airport</option> <option value="Stanstead Airport">Stanstead Airport</option> <option value="Luton International Airport">Luton Airport</option> </select> </p> <p> <input type="text" value="From" name="address1"><br> <p> <select onChange="to(this.form)" name="end"> <option selected="selected">Select a Destination</option> <option value="Leeds Bradford Airport">Leeds Bradford Airport</option> <option value="Manchester Airport">Manchester Airport</option> <option value="Teesside International Airport">Teeside Airport</option> <option value="Liverpool John Lennon Airport">Liverpool Airport</option> <option value="East Midlands Airport">East Midlands Airport</option> <option value="Heathrow International Airport">Heathrow Airport</option> <option value="Gatwick Airport">Gatwick Airport</option> <option value="Stanstead Airport">Stanstead Airport</option> <option value="Luton International Airport">Luton Airport</option> </select> </p> <input type="text" value="To" name="address2"><br> <input type="hidden" value=" uk" name="uk"> <br> <input type="submit" value="Get Quote"> <input type="button" value="Reset" onClick="resetpage()"><br /><br /> <input type="submit" id="CBSubmit" value="Confirm and Book" action=""/> </p> </form> <p id="from"><strong>From:</strong></p> <p id="to"><strong>To:</strong></p> <p id="miles"><strong>Distance: </strong></p> <p id="cost"><span class="fare"><strong>Estimated Taxi FARE:</strong></span></p> <p id="results"></p> <div class="style4" style="width: 500px; height: 500px; position: relative; background-color: rgb(229, 227, 223);" id="map_canvas"></div> </div> </div> Code for Booking Form: <form method="post" action="contactengine.php" id="contact_form"> <p> <label for="Name" id="Name">Name:</label> <input type="text" name="Name" /> <label for="Email" id="Email">Email:</label> <input type="text" name="Email" /> <label for="tel" id="tel">Tel No:</label> <input type="text" name="tel" /><br /><br /> <label for="from" id="from">Pickup Point:</label> <input type="text" name="from" value="" /><br /><br /> <label for="to" id="to">Destination:</label> <input type="text" name="to" value=""/><br /> <label for="passengers" id="passengers">No. of passengers</label> <input type="text" name="passengers" /><br /><br /> <label for="quote" id="quote">Price of journey:</label> <input type="text" name="quote" value="" /><br /><br /> <label for="Message" id="Message">Any other info:</label> <textarea name="Message" rows="20" cols="40"></textarea> <br /> Are you an account holder?<br /> <label for="account" id="yes" /> Yes:</label> <input type="radio" class="radio" value="yes" name="account"> <label for="account" id="yes" /> No:</label> <input type="radio" class="radio" value="no" name="account"> </p> <small>Non-account holders will have to pay a £5 booking fee when confirming thier booking</small> <input type="submit" name="submit" value="Submit" class="submit-button" /> </p> </form> Thanks in advance

    Read the article

< Previous Page | 1 2 3