(X)HTML, JavaScript, DHTML, XML, CSS Client scripting tehnologije, Dynamic HTML, Cascading Stylesheets, XML i standardi |
|
Alati teme | Način prikaza |
03. 07. 2011. | #1 |
expert
Expert
Datum učlanjenja: 15.03.2011
Poruke: 518
Hvala: 16
20 "Hvala" u 17 poruka
|
Google mapa sa v2 u v3
Problem je sledeci:
Imam ovaj kod: <!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 Mapa</title> <script src="http://maps.google.com/maps?file=api&v=2&key=abcdef" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ var map; var geocoder; function load() { if (GBrowserIsCompatible()) { geocoder = new GClientGeocoder(); map = new GMap2(document.getElementById('map')); map.addControl(new GSmallMapControl()); map.addControl(new GMapTypeControl()); map.setCenter(new GLatLng(40, -100), 4); } } function searchLocations() { var address = document.getElementById('addressInput').value; geocoder.getLatLng(address, function(latlng) { if (!latlng) { alert(address + ' not found'); } else { searchLocationsNear(latlng); } }); } function searchLocationsNear(center) { var radius = document.getElementById('radiusSelect').value; var searchUrl = 'phpsqlsearch_genxml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius; GDownloadUrl(searchUrl, function(data) { var xml = GXml.parse(data); var markers = xml.documentElement.getElementsByTagName('marker') ; map.clearOverlays(); var sidebar = document.getElementById('sidebar'); sidebar.innerHTML = ''; if (markers.length == 0) { sidebar.innerHTML = 'No results found.'; map.setCenter(new GLatLng(40, -100), 4); return; } var bounds = new GLatLngBounds(); for (var i = 0; i < markers.length; i++) { var name = markers[i].getAttribute('name'); var address = markers[i].getAttribute('address'); var distance = parseFloat(markers[i].getAttribute('distance')); var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')), parseFloat(markers[i].getAttribute('lng'))); var marker = createMarker(point, name, address); map.addOverlay(marker); var sidebarEntry = createSidebarEntry(marker, name, address, distance); sidebar.appendChild(sidebarEntry); bounds.extend(point); } map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds)); }); } function createMarker(point, name, address) { var marker = new GMarker(point); var html = '<b>' + name + '</b> <br/>' + address; GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(html); }); return marker; } function createSidebarEntry(marker, name, address, distance) { var div = document.createElement('div'); var html = '<b>' + name + '</b> (' + distance.toFixed(1) + ')<br/>' + address; div.innerHTML = html; div.style.cursor = 'pointer'; div.style.marginBottom = '5px'; GEvent.addDomListener(div, 'click', function() { GEvent.trigger(marker, 'click'); }); GEvent.addDomListener(div, 'mouseover', function() { div.style.backgroundColor = '#eee'; }); GEvent.addDomListener(div, 'mouseout', function() { div.style.backgroundColor = '#fff'; }); return div; } //]]> </script> </head> <body onload="load()" onunload="GUnload()"> Address: <input type="text" id="addressInput"/> Radius: <select id="radiusSelect"> <option value="25" selected>25</option> <option value="100">100</option> <option value="200">200</option> </select> <input type="button" onclick="searchLocations()" value="Search Locations"/> <br/> <br/> <div style="width:600px; font-family:Arial, sans-serif; font-size:11px; border:1px solid black"> <table> <tbody> <tr id="cm_mapTR"> <td width="200" valign="top"> <div id="sidebar" style="overflow: auto; height: 400px; font-size: 11px; color: #000"></div> </td> <td> <div id="map" style="overflow: hidden; width:400px; height:400px"></div> </td> </tr> </tbody> </table> </div> </body> </html> i dobija se ovako nesto: Medjutim zelim da mapu prebacim u google v3 api kao ovde: http://code.google.com/apis/maps/art...search_v3.html s tim da levi meni ostane isti kao u gore prikazanom kodu a ne kao opcija koja se bira kao na ovoj slici: Ja sam pokusavao razne kombinacije ova dva koda ali nikako da uspem i neznam sta usvrari treba promeniti kod v3 koda da bi se pojavio meni sa leve strane kao u prvoj slici koju sam postavio. |
03. 07. 2011. | #2 |
banned
Professional
Datum učlanjenja: 04.06.2005
Poruke: 371
Hvala: 0
738 "Hvala" u 83 poruka
|
Postavi jednu od tih kombinacija da bi videli gde grešiš.
Možda nešto kao: HTML kôd:
<!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"/> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <title>Google Maps AJAX + mySQL/PHP Example</title> <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ var map; var markers = []; var infoWindow; var locationSelect; var sidebar; function load() { map = new google.maps.Map(document.getElementById("map"), { center: new google.maps.LatLng(40, -100), zoom: 4, mapTypeId: 'roadmap', mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU} }); infoWindow = new google.maps.InfoWindow(); sidebar = document.getElementById("sidebar"); } function searchLocations() { var address = document.getElementById("addressInput").value; var geocoder = new google.maps.Geocoder(); geocoder.geocode({address: address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { searchLocationsNear(results[0].geometry.location); } else { alert(address + ' not found'); } }); } function clearLocations() { infoWindow.close(); for (var i = 0; i < markers.length; i++) { markers[i].setMap(null); } markers.length = 0; sidebar.innerHTML = ""; } function searchLocationsNear(center) { clearLocations(); var radius = document.getElementById('radiusSelect').value; var searchUrl = 'phpsqlsearch_genxml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius; downloadUrl(searchUrl, function(data) { var xml = parseXml(data); var markerNodes = xml.documentElement.getElementsByTagName("marker"); var bounds = new google.maps.LatLngBounds(); for (var i = 0; i < markerNodes.length; i++) { var name = markerNodes[i].getAttribute("name"); var address = markerNodes[i].getAttribute("address"); var distance = parseFloat(markerNodes[i].getAttribute("distance")); var latlng = new google.maps.LatLng( parseFloat(markerNodes[i].getAttribute("lat")), parseFloat(markerNodes[i].getAttribute("lng"))); createMarker(latlng, name, address); createSidebar(name, distance, address, i); bounds.extend(latlng); } map.fitBounds(bounds); }); } function createMarker(latlng, name, address) { var html = "<b>" + name + "</b> <br/>" + address; var marker = new google.maps.Marker({ map: map, position: latlng }); google.maps.event.addListener(marker, 'click', function() { infoWindow.setContent(html); infoWindow.open(map, marker); }); markers.push(marker); } function createSidebar(name, distance, address, num) { var div = document.createElement('div'); var html = '<b>' + name + '</b> (' + distance.toFixed(1) + ')<br/>' + address; div.innerHTML = html; div.style.cursor = 'pointer'; div.style.marginBottom = '5px'; google.maps.event.addDomListener(div, 'click', function(e) { google.maps.event.trigger(markers[num], 'click'); }); google.maps.event.addDomListener(div, 'mouseover', function(e) { div.style.backgroundColor = '#eee'; }); google.maps.event.addDomListener(div, 'mouseout', function(e) { div.style.backgroundColor = '#fff'; }); sidebar.appendChild(div); } function downloadUrl(url, callback) { var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest; request.onreadystatechange = function() { if (request.readyState == 4) { request.onreadystatechange = doNothing; callback(request.responseText, request.status); } }; request.open('GET', url, true); request.send(null); } function parseXml(str) { if (window.ActiveXObject) { var doc = new ActiveXObject('Microsoft.XMLDOM'); doc.loadXML(str); return doc; } else if (window.DOMParser) { return (new DOMParser).parseFromString(str, 'text/xml'); } } function doNothing() {} //]]> </script> </head> <body style="margin:0px; padding:0px;" onload="load()"> <div style="padding:5px;"> Address: <input type="text" id="addressInput"/> Radius: <select id="radiusSelect"> <option value="25" selected>25mi</option> <option value="100">100mi</option> <option value="200">200mi</option> </select> <input type="button" onclick="searchLocations()" value="Search Locations"/> </div> <div style="width:600px; font-family:Arial, sans-serif; font-size:11px; border:1px solid black"> <table> <tr> <td width="200"> <div id="sidebar" style="overflow: auto; height: 400px; font-size: 11px; color: #000"></div> </td> <td> <div id="map" style="width: 400px; height: 400px"></div> </td> </tr> </table> </div> </body> </html>
__________________
Don't look at me; I'm lost too. “If you can't dazzle them with brilliance, baffle them with bul*s**t.” |
03. 07. 2011. | #3 |
expert
Expert
Datum učlanjenja: 15.03.2011
Poruke: 518
Hvala: 16
20 "Hvala" u 17 poruka
|
Hvala... uz malo izmena to je to!
|
03. 07. 2011. | #4 |
expert
Expert
Datum učlanjenja: 15.03.2011
Poruke: 518
Hvala: 16
20 "Hvala" u 17 poruka
|
Problem jedino prave checkboxovi za kategorije (barovi,restorani) i kada stavim ovo jednostavno nemogu da koristim geocoder: http://kuponik.adriamart.com/111.html inace bez ovoga radi dobro... jos jednom hvala
|
04. 07. 2011. | #5 |
banned
Professional
Datum učlanjenja: 04.06.2005
Poruke: 371
Hvala: 0
738 "Hvala" u 83 poruka
|
Prvo obrati pažnju na html kod, meni npr u ff nije htelo da prikaže mapu.
Zatim promenljivu type iz funkcije searchLocationsNear potrebno je proslediti funkciji createMarker, pa dodaj još jedan argument createMarker funkciji i prilikom poziva nje unutar funkcije searchLocationsNear prosledi promenljivu type, dakle kod: Kôd:
createMarker(latlng, name, address); Kôd:
createMarker(latlng, name, address, type); Kôd:
function createMarker(latlng, name, address) Kôd:
function createMarker(latlng, name, address, type) Kod: Kôd:
if(typeof markerGroups[type] !== 'undefined') { markerGroups[type].push(marker); } Kôd:
google.maps.event.addListener(marker, 'click', function() { infoWindow.setContent(html); infoWindow.open(map, marker); if(typeof markerGroups[type] !== 'undefined') { markerGroups[type].push(marker); } }); Kôd:
if(typeof markerGroups[type] !== 'undefined') { markerGroups[type].push(marker); } google.maps.event.addListener(marker, 'click', function() { infoWindow.setContent(html); infoWindow.open(map, marker); }); Ne znam kao si zamislio za sidebar-om, ali sada će nastati problem jer klikom na neku od stavki u istom i dalje će se prikazivati infoWindow bez obzira da li je marker prikazan ili sakriven, zato ispitaj prvo da li je marker vidljiv pa onda prikaži infoWindow. Zatim ukoliko je infoWindow vidljiv a marker za isti se uklanja info window ostaje vidljiv, zato kada uklanjaš marker uklanjaj i infoWindow.
__________________
Don't look at me; I'm lost too. “If you can't dazzle them with brilliance, baffle them with bul*s**t.” |
04. 07. 2011. | #6 |
expert
Expert
Datum učlanjenja: 15.03.2011
Poruke: 518
Hvala: 16
20 "Hvala" u 17 poruka
|
Negde gresim verovatno... jer neradi a ni ikonice se ne menjaju prema type-u, a sto se tice infowindow-a ubacicu infoboxove jer mi oni jquery prozori i nisu bas najbolje resenje bar po meni. Hteo sam da ubacim ovo sa radiusom jer kada budem imao u bazi mnogo markera nema potrebe da se svi pojavljuju na mapi npr. markeri iz hrvatske,slovenije kada su potrebni samo iz beograda ... e sad jedini je problem sto je google limitirao koriscenje geocodera na 2500 upita dnevno
Tebi hvala mnogo na trudu koji si ulozio, ako nekada nesto bude od ovog projekta imas 50% |
04. 07. 2011. | #7 |
banned
Professional
Datum učlanjenja: 04.06.2005
Poruke: 371
Hvala: 0
738 "Hvala" u 83 poruka
|
Da li u xml fajlu imaš definisane tipove (type atribut)? Pokušao sam par pretraga i vidim atribut type ali ništa nije definisano.
Što se tiče ikonica umesto: Kôd:
var marker = new google.maps.Marker({ map: map, position: latlng }); Kôd:
var marker = new google.maps.Marker({ map: map, icon: icon.icon, position: latlng });
__________________
Don't look at me; I'm lost too. “If you can't dazzle them with brilliance, baffle them with bul*s**t.” |
04. 07. 2011. | #8 |
expert
Expert
Datum učlanjenja: 15.03.2011
Poruke: 518
Hvala: 16
20 "Hvala" u 17 poruka
|
U fajlu koji generise xml postoji definisan type:
$newnode->setAttribute("type", $row['type']); ... |
04. 07. 2011. | #9 |
banned
Professional
Datum učlanjenja: 04.06.2005
Poruke: 371
Hvala: 0
738 "Hvala" u 83 poruka
|
Da vidim da postoji u xml fajlu ali nema nikavu vrednost, kao što sam gore napisao, mada pokušao sam svega par pretraga.
Da li $row['type'] ima neku vrednost? Evo npr. deo xml fajla, prilikom jedne od pretraga: Kôd:
... <marker name="490 din umesto 1860 din za sat vremena kuglanja za 6 osoba u Colosseum Bowling centru." address="slike/4484862.jpg" lat="44.84862" lng="20.39871" type="" distance="3.99888258221121"/> <marker name="490 din umesto 1860 din za sat vremena kuglanja za 6 osoba u Colosseum Bowling centru." address="slike/4484862.jpg" lat="44.84862" lng="20.39871" type="" distance="3.99888258221121"/> <marker name="1.075 din umesto 2.500 din za celodnevnu kartu skijanja na vodi u Aqua ski centru. Provedite dan na najbolji nacin." address="slike/4477674.jpg" lat="44.77674" lng="20.37482" type="" distance="5.07825070983292"/> <marker name="1.075 din umesto 2.500 din za celodnevnu kartu skijanja na vodi u Aqua ski centru. Provedite dan na najbolji nacin." address="slike/4477674.jpg" lat="44.77674" lng="20.37482" type="" distance="5.07825070983292"/> ...
__________________
Don't look at me; I'm lost too. “If you can't dazzle them with brilliance, baffle them with bul*s**t.” |
04. 07. 2011. | #10 |
expert
Expert
Datum učlanjenja: 15.03.2011
Poruke: 518
Hvala: 16
20 "Hvala" u 17 poruka
|
Pojedini markeri su definisani sa type a pojedini nisu... evo sad sam ispraznio mysql bazu i ponovo postavio markere tako da svi (5) imaju vrednost type='bar' ali checkboxovi koji trebna da ih iskljuce ili ukljuce nerade
|
|
|