<script type="text/javascript">
window.onDomReady = DomReady;
function DomReady(func) { if(document.addEventListener) { document.addEventListener("DOMContentLoaded", func, false); } else { document.onreadystatechange = function() { readyState(func) } } }
function readyState(func) { if(document.readyState == "complete") { func(); } }
</script>
<script src=\"{$baseAddresse}/maps?file=api&v={$map_api_version}&key={$config->googleMapsApiKey}\" type=\"text/javascript\">
</script>
<script type="text/javascript">
google.load("search", "1.x", {callback: initialize});
function initialize() {
if (google.loader.ClientLocation) {
var lat = google.loader.ClientLocation.latitude;
var long = google.loader.ClientLocation.longitude;
alert ("lat: " + lat + "\nlong: " + long);
}
else { alert ("not available"); }
}
</script>
<?php
//if ($mapControl == 3) {
// echo "<script src=\"{$config->liveSite}/modules/{$module_path}extlargemapcontrol.js\" type=\"text/javascript\"></script>";
//}
echo "\n\t <script type=\"text/javascript\">";
echo "\n\t ";
echo "//<![CDATA[ ";
echo "\n\t\t ";
echo "function loadSobiCatOverMap() {";
echo "\n\t\t\t ";
echo "if ( GBrowserIsCompatible() ) {";
echo "\n\t\t\t\t ";
echo "var SobiCatOverMap = new GMap2( document.getElementById(\"sobi2GcatOver\") );";
echo "\n\t\t\t\t ";
echo "SobiCatOverMap.setCenter( new GLatLng( {$centerPointLat}, {$centerPointLong} ), {$mapsZoom} );";
<?php function JomSocial_field($fieldcode) {
global $database;
$user =& JFactory::getUser();
$userId = $user->get( 'id' );
$sql = "SELECT (id) FROM #__community_fields WHERE fieldcode= '$fieldcode'";
$database->setQuery( $sql );
$fieldID = $database->loadResult();
$sql = "SELECT (value) FROM #__community_fields_values WHERE field_id= {$fieldID} && user_id= {$userId}";
$database->setQuery( $sql );
echo $database->loadResult();
}
?>
<?php JomSocial_field("FIELD_COUNTRY"); ?>
<?php JomSocial_field("FIELD_CITY"); ?>
<?php JomSocial_field("FIELD_ADDRESS"); ?>
map.setCenter(new GLatLng(42.93230, 12.71118), 5);
ovviamente latitudine e longitudine le devi ricavare con apposite funzioni di geodecoding.... google.loader.ClientLocation.latitude;
$centerPointLat = google.loader.ClientLocation.latitude;
google.loader.ClientLocation.longitude;
$centerPointLong = google.loader.ClientLocation.longitude;
echo "SobiCatOverMap.setCenter( new GLatLng( {$centerPointLat}, {$centerPointLong} ), {$mapsZoom} );";
mi da lo spazio della mappa grigio con il logo di Google.. se metto il codice dove dichiara i parametri del modulo mi ritorna la mappa come se non avessi modificato nulla. (@Zeus: nel modulo c'è già quel comando per centrare la mappa, devo capire come passargli gli indirizzi)function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
google.loader.ClientLocation.latitude;e mi restituisce la mappa tutta grigia..
$centerPointLat = google.loader.ClientLocation.latitude;
google.loader.ClientLocation.longitude;
$centerPointLong = google.loader.ClientLocation.longitude;
$mapsZoom = "5";
echo "SobiCatOverMap.setCenter( new GLatLng( {$centerPointLat}, {$centerPointLong} ), {$mapsZoom} );";
<script src="http://www.google.com/jsapi" language="javascript"></script>
<script language="javascript">
if (google.loader.ClientLocation != null) {
document.write("Your Location Is: " + google.loader.ClientLocation.address.city + ", " + google.loader.ClientLocation.address.region);
} else {
document.write("Your Location Was Not Detected By Google Loader");
}
</script>
If a location cannot be determined from the visitors IP address, the google.loader.ClientLocation variable will be null.vuol dire che io ho qualche blocco che nega la lettura del mio IP??
echo "<script src=\"{$baseAddresse}/maps?file=api&v={$map_api_version}&key={$config->googleMapsApiKey}\" type=\"text/javascript\"></script>";
nel modulo c'è già questo richiamo alla chiave, giusto no?GDownloadUrl("xml.php?", function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var marker = createMarker(point);
map.addOverlay(marker);
}
});
ovviamente nel file xml devi restituire in output un elemento chiamato marker con gli attributi lat e lng, più eventuali altri campi che ti possono servire per il fumetto associato al marker.Ma non basta che alla riga 424 sostituisci {$centerPointLat}, {$centerPointLong} con le coordinate che prendi dal tuo script? ovviamente devi aggiungere al modulo un tuo javascript per rilevare la currentlocation (praticamente come hai fatto nel file new.php).
magari fai prima una prova scrivendo direttamente le coordinate... e poi se funziona preoccupati del come integrare il tutto.
altrimenti, se sai dove sono salvate le coordinate di SOBI potresti adottare la stessa soluzione che ho usato io nel mio sito http://www.campiscout.com (http://www.campiscout.com/) (sempre che non mi censurino anche questo link).
in pratica ti generi dinamicamente un file xml (xml.php) che recupera le coordinate dal db e lo dai in pasto ad un loop e per ogni record esegui la funzione create marker per visualizzare il marker....
alert(coordinate);
e vediamo se ti restituisce qualcosa (mettilo alla riga 513 - appena sopra alla chiamata echo "var SobiCatOverMap = new GMap2( document.getElementById(\"sobi2GcatOver\") );";
)cmq avrei bisogno di vedere il rendering... hai un link per farmi vedere il problema?
$documento =& JFactory::getDocument();
$documento->addScript('http://code.google.com/apis/gears/gears_init.js');
$javascript ="
var coordinate = null;
function getLocale(){
if ( navigator ) {
if ( navigator.userLanguage ) {
return navigator.userLanguage.toLowerCase();
}
else if ( navigator.language ) {
return navigator.language.toLowerCase();
}
else if ( navigator.browserLanguage ) {
return navigator.browserLanguage.toLowerCase();
}
else if ( navigator.systemLanguage ) {
return navigator.systemLanguage.toLowerCase();
}
}
return \"unknown\";
}
var locales = new Object();
locales[\"en-gb\"] = {lat:54.559322587438636, lng:-4.1748046875, location:\"United Kingdom\"};
locales[\"en-us\"] = {lat:38.41055825094609, lng:-100.37109375, location:\"USA\"};
// TODO - more locales
function TryGoogleLoader(){
if (google.loader.ClientLocation != null) {
var address = google.loader.ClientLocation.address;
var yourLocation = address.city + \", \" + address.region + \", \" + address.country;
document.getElementById(\"location\").innerHTML = \"Your location (using Google loader) is \" + yourLocation;
var latLong = new google.maps.LatLng(google.loader.ClientLocation.latitude,
google.loader.ClientLocation.longitude);
//showMap(latLong, 12);
coordinate = latLong;
}
else {
// map locale to location
var locale = getLocale();
if (locales[locale] != null) {
var latLong = new google.maps.LatLng(locales[locale].lat, locales[locale].lng);
document.getElementById(\"location\").innerHTML =
\"Guessing your location based on your locale - \" + locales[locale].location;
//showMap(latLong, 5);
coordinate = latLong;
}
else {
document.getElementById(\"location\").innerHTML = \"Your location can not be found - locale is \" + locale;
}
}
}
function TryGoogleGears(){
if (google.gears) {
// Try Google Gears Geolocation
var geo = google.gears.factory.create('beta.geolocation');
geo.getCurrentPosition(function(position) {
var latLong = new google.maps.LatLng(position.latitude, position.longitude);
document.getElementById(\"location\").innerHTML = \"Found location via Google Gears\";
//showMap(latLong, 15);
coordinate = latLong;
}, function() {
TryGoogleLoader();
});
}
else
TryGoogleLoader();
}
";
$documento->addScriptDeclaration($javascript);
cmq, come dicevi tu, mi sa tanto che devi provare a usare la mappa dello script e a pubblicarci su i markers...
$query = "SELECT `data_txt`, `itemid`, `fieldid` FROM `#__sobi2_fields_data` WHERE (`fieldid` = 1 OR `fieldid` = '{$config->googleMapsLatField}' OR `fieldid` = '{$config->googleMapsLongField}') AND `itemid` IN ($sItems)";
$query = "SELECT `title`, `icon`, `itemid` FROM `#__sobi2_item` WHERE (`itemid` IN ($sItems) AND `published` = 1 AND (`publish_down` > '{$now}' OR `publish_down` = '{$config->nullDate}') )";
// Change this depending on the name of your PHP file
downloadUrl("phpsqlajax_genxml.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagNam e("marker");
ma quindi questo non mi serve, però come hai fatto
tu a fargli caricare il ciclo con le tue tabelle se non usi un xml come markers?
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 google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "" + name + " [br /]" + address;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
// Change this depending on the name of your PHP file
downloadUrl("phpsqlajax_genxml.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagNam e("marker");
ma quindi questo non mi serve, però come hai fatto
tu a fargli caricare il ciclo con le tue tabelle se non usi un xml come markers?
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 google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "" + name + " [br /]" + address;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
Ma io showmap l'avevo eliminato, spostando il codice nella funzione SOBI... altrimenti ti avrebbe caricato 2 mappe.
Domani dovrei riuscire a trovare un pò di tempo per provare le cose...