php e google maps

LaKanka

Utente Attivo
29 Ago 2008
166
0
0
Ciao a tutti!!
E sopprattutto a chi mi illuminerà sul mio problema..
Ho creato un sito in php ,tratta immobili, ed ho form dove l'utente può inserire l'immobile con il relativo indirizzo..
Salvo tutto nel database.. Ciò che inserisce l'utente poi lo pubblico nella home..
Il mio problema è che per ogni immobile ho il pulsante dettagli dove dovrebbe esserci la mappa di google già col rispettivo indirizzo..
C'è un modo per uscirne vivi??
Mi sto scervellando da questa mattina senza venirne a capo..:incazz2:
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
io ho risolto in questa maniera
da google maps copio il codice della mappa con l'indirizzo
incollo in un file .txt (blocco note) e lo denomino
mappa_IDCLIENTE.txt dove IDCLIENTE è l'id del record cliente e lo salvo nella cartella del cliente

nel punto in cui voglio che appaia la mappa (o entro tabella o entro div)

scrivo

PHP:
<?php
	@include_once "cart_".$id_D."/mappa_".$id_D.".txt";
	if (!file_exists("cart_".$id_D."/mappa_".$id_D.".txt")) {
    		echo "mappa in preparazione";
		}
	?>

non posso dirti qui dove vedere su un mio sito come appare
:beer:
 

LaKanka

Utente Attivo
29 Ago 2008
166
0
0
ok grazie comunque per la risp.. ma così facendo dovrei comunque per ogni indirizzo inserito andare a scaricare il codice da google maps.. ma era proprio quello che volevo evitare..
Probabilmente non c'è soluzione per il mio problema.. almeno così mi hanno detto..
 

nicola.firenze

Nuovo Utente
14 Set 2008
6
0
0
vediamo se posso aiutarti

Ciao di solito non programmo in php, ma se ti può essere utile google mette a disposizione delle "api" che servono appunto per ricavare quello che serve a te. Dai un'occhiata a questo link.
Buon lavoro,
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao nicola.firenze

ho guardato il link, ma non ci hi capito molto (non vado molto d'accordo con l'inglese:boxing:), puoi dare un po di delucidazioni? e inviare un link in cui cìè qualche applicazione?
grazie




...la mi porti un bacione a firenze...
 

nicola.firenze

Nuovo Utente
14 Set 2008
6
0
0
Vediamo

allora, devi inserire il codice php, nella tua pagina dove vuoi che compai la carta dell'immobile. Ti mando un esempio

<?php /**
* Showing multiple points with Phoogle Maps
* class developed by Justin Johnson <[email protected]>
*/

require_once 'phoogle.php';

$map = new PhoogleMap();
$map->setAPIKey("ABQIAAAA0ksKqHM3yT_xmOPe0DANGRRMlCWGe88WcLmN582t1mFB9gpW6hTvRlzTS-LCJ8nFoD2AGi5vq0X-Yg");
?>
<!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>
<? $map->printGoogleJS(); ?>
</head>
<body>
<?

$map->addAddress('Via Frusa 22, Firenze');
//$map->addAddress('210 Doster Ave, Mooresville, NC 28115');
//$map->addAddress('300 Dingler Ave, Mooresville, NC 28115');
$map->showMap();

?>
</body>

</html>

La variable $map contiene l'indirizzo dell'immobile

dopo di che devi copiare nello stesso folder anche il file phoogle.php che lo puoi scaricare da qui http://www.systemsevendesigns.com/phoogle

oppure ne crei uno e ci copi dentro questo

<?php

/**
* Phoogle Maps 2.0 | Uses Google Maps API to create customizable maps
* that can be embedded on your website
* Copyright (C) 2005 Justin Johnson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
* Phoogle Maps 2.0
* Uses Google Maps Mapping API to create customizable
* Google Maps that can be embedded on your website
*
* @class Phoogle Maps 2.0
* @author Justin Johnson <[email protected]>
* @copyright 2005 system7designs
*/




class PhoogleMap{
/**
* validPoints : array
* Holds addresses and HTML Messages for points that are valid (ie: have longitude and latitutde)
*/
var $validPoints = array();
/**
* invalidPoints : array
* Holds addresses and HTML Messages for points that are invalid (ie: don't have longitude and latitutde)
*/
var $invalidPoints = array();
/**
* mapWidth
* width of the Google Map, in pixels
*/
var $mapWidth = 300;
/**
* mapHeight
* height of the Google Map, in pixels
*/
var $mapHeight = 300;

/**
* apiKey
* Google API Key
*/
var $apiKey = "";

/**
* showControl
* True/False whether to show map controls or not
*/
var $showControl = true;

/**
* showType
* True/False whether to show map type controls or not
*/
var $showType = true;
/**
* controlType
* string: can be 'small' or 'large'
* display's either the large or the small controls on the map, small by default
*/

var $controlType = 'small';

/**
* zoomLevel
* int: 0-17
* set's the initial zoom level of the map
*/

var $zoomLevel = 4;




/**
* @function addGeoPoint
* @description Add's an address to be displayed on the Google Map using latitude/longitude
* early version of this function, considered experimental
*/

function addGeoPoint($lat,$long,$infoHTML){
$pointer = count($this->validPoints);
$this->validPoints[$pointer]['lat'] = $lat;
$this->validPoints[$pointer]['long'] = $long;
$this->validPoints[$pointer]['htmlMessage'] = $infoHTML;
}

/**
* @function centerMap
* @description center's Google Map on a specific point
* (thus eliminating the need for two different show methods from version 1.0)
*/

function centerMap($lat,$long){
$this->centerMap = "map.centerAndZoom(new GPoint(".$long.",".$lat."), ".$this->zoomLevel.");\n";
}


/**
* @function addAddress
* @param $address:string
* @returns Boolean True:False (True if address has long/lat, false if it doesn't)
* @description Add's an address to be displayed on the Google Map
* (thus eliminating the need for two different show methods from version 1.0)
*/
function addAddress($address,$htmlMessage=null){
if (!is_string($address)){
die("All Addresses must be passed as a string");
}
$apiURL = "http://maps.google.com/maps/geo?&output=xml&key=".$this->apiKey."&q=";
$addressData = file_get_contents($apiURL.urlencode($address));

$results = $this->xml2array(utf8_encode($addressData));
if (empty($results['kml'][Response]['Placemark']['Point']['coordinates'])){
$pointer = count($this->invalidPoints);
$this->invalidPoints[$pointer]['lat']= $results['kml'][Response]['Placemark']['Point']['coordinates'][0];
$this->invalidPoints[$pointer]['long']= $results['kml'][Response]['Placemark']['Point']['coordinates'][1];
$this->invalidPoints[$pointer]['passedAddress'] = $address;
$this->invalidPoints[$pointer]['htmlMessage'] = $htmlMessage;
}else{
$pointer = count($this->validPoints);
$this->validPoints[$pointer]['lat']= $results['kml'][Response]['Placemark']['Point']['coordinates'];
$this->validPoints[$pointer]['long']= $results['kml'][Response]['Placemark']['Point']['coordinates'];
$this->validPoints[$pointer]['passedAddress'] = $address;
$this->validPoints[$pointer]['htmlMessage'] = $htmlMessage;
}


}
/**
* @function showValidPoints
* @param $displayType:string
* @param $css_id:string
* @returns nothing
* @description Displays either a table or a list of the address points that are valid.
* Mainly used for debugging but could be useful for showing a list of addresses
* on the map
*/
function showValidPoints($displayType,$css_id){
$total = count($this->validPoints);
if ($displayType == "table"){
echo "<table id=\"".$css_id."\">\n<tr>\n\t<td>Address</td>\n</tr>\n";
for ($t=0; $t<$total; $t++){
echo"<tr>\n\t<td>".$this->validPoints[$t]['passedAddress']."</td>\n</tr>\n";
}
echo "</table>\n";
}
if ($displayType == "list"){
echo "<ul id=\"".$css_id."\">\n";
for ($lst=0; $lst<$total; $lst++){
echo "<li>".$this->validPoints[$lst]['passedAddress']."</li>\n";
}
echo "</ul>\n";
}
}
/**
* @function showInvalidPoints
* @param $displayType:string
* @param $css_id:string
* @returns nothing
* @description Displays either a table or a list of the address points that are invalid.
* Mainly used for debugging shows only the points that are NOT on the map
*/
function showInvalidPoints($displayType,$css_id){
$total = count($this->invalidPoints);
if ($displayType == "table"){
echo "<table id=\"".$css_id."\">\n<tr>\n\t<td>Address</td>\n</tr>\n";
for ($t=0; $t<$total; $t++){
echo"<tr>\n\t<td>".$this->invalidPoints[$t]['passedAddress']."</td>\n</tr>\n";
}
echo "</table>\n";
}
if ($displayType == "list"){
echo "<ul id=\"".$css_id."\">\n";
for ($lst=0; $lst<$total; $lst++){
echo "<li>".$this->invalidPoints[$lst]['passedAddress']."</li>\n";
}
echo "</ul>\n";
}
}
/**
* @function setWidth
* @param $width:int
* @returns nothing
* @description Sets the width of the map to be displayed
*/
function setWidth($width){
$this->mapWidth = $width;
}
/**
* @function setHeight
* @param $height:int
* @returns nothing
* @description Sets the height of the map to be displayed
*/
function setHeight($height){
$this->mapHeight = $height;
}
/**
* @function setAPIkey
* @param $key:string
* @returns nothing
* @description Stores the API Key acquired from Google
*/
function setAPIkey($key){
$this->apiKey = $key;
}
/**
* @function printGoogleJS
* @returns nothing
* @description Adds the necessary Javascript for the Google Map to function
* should be called in between the html <head></head> tags
*/
function printGoogleJS(){
echo "\n<script src=\"http://maps.google.com/maps?file=api&v=2&key=".$this->apiKey."\" type=\"text/javascript\"></script>\n";
}
/**
* @function showMap
* @description Displays the Google Map on the page
*/
function showMap(){
echo "\n<div id=\"map\" style=\"width: ".$this->mapWidth."px; height: ".$this->mapHeight."px\">\n</div>\n";
echo " <script type=\"text/javascript\">\n
function showmap(){
//<![CDATA[\n
if (GBrowserIsCompatible()) {\n
var map = new GMap(document.getElementById(\"map\"));\n";
if (empty($this->centerMap)){
echo "map.centerAndZoom(new GPoint(".$this->validPoints[0]['long'].",".$this->validPoints[0]['lat']."), ".$this->zoomLevel.");\n";
}else{
echo $this->centerMap;
}
echo "}\n
var icon = new GIcon();
icon.image = \"http://labs.google.com/ridefinder/images/mm_20_red.png\";
icon.shadow = \"http://labs.google.com/ridefinder/images/mm_20_shadow.png\";
icon.iconSize = new GSize(12, 20);
icon.shadowSize = new GSize(22, 20);
icon.iconAnchor = new GPoint(6, 20);
icon.infoWindowAnchor = new GPoint(5, 1);

";
if ($this->showControl){
if ($this->controlType == 'small'){echo "map.addControl(new GSmallMapControl());\n";}
if ($this->controlType == 'large'){echo "map.addControl(new GLargeMapControl());\n";}

}
if ($this->showType){
echo "map.addControl(new GMapTypeControl());\n";
}

$numPoints = count($this->validPoints);
for ($g = 0; $g<$numPoints; $g++){
echo "var point".$g." = new GPoint(".$this->validPoints[$g]['long'].",".$this->validPoints[$g]['lat'].")\n;
var marker".$g." = new GMarker(point".$g.");\n
map.addOverlay(marker".$g.")\n
GEvent.addListener(marker".$g.", \"click\", function() {\n";
if ($this->validPoints[$g]['htmlMessage']!=null){
echo "marker".$g.".openInfoWindowHtml(\"".$this->validPoints[$g]['htmlMessage']."\");\n";
}else{
echo "marker".$g.".openInfoWindowHtml(\"".$this->validPoints[$g]['passedAddress']."\");\n";
}
echo "});\n";
}
echo " //]]>\n
}
window.onload = showmap;
</script>\n";
}
///////////THIS BLOCK OF CODE IS FROM Roger Veciana's CLASS (assoc_array2xml) OBTAINED FROM PHPCLASSES.ORG//////////////
function xml2array($xml){
$this->depth=-1;
$this->xml_parser = xml_parser_create();
xml_set_object($this->xml_parser, $this);
xml_parser_set_option ($this->xml_parser,XML_OPTION_CASE_FOLDING,0);//Don't put tags uppercase
xml_set_element_handler($this->xml_parser, "startElement", "endElement");
xml_set_character_data_handler($this->xml_parser,"characterData");
xml_parse($this->xml_parser,$xml,true);
xml_parser_free($this->xml_parser);
return $this->arrays[0];

}
function startElement($parser, $name, $attrs){
$this->keys[]=$name;
$this->node_flag=1;
$this->depth++;
}
function characterData($parser,$data){
$key=end($this->keys);
$this->arrays[$this->depth][$key]=$data;
$this->node_flag=0;
}
function endElement($parser, $name)
{
$key=array_pop($this->keys);
if($this->node_flag==1){
$this->arrays[$this->depth][$key]=$this->arrays[$this->depth+1];
unset($this->arrays[$this->depth+1]);
}
$this->node_flag=1;
$this->depth--;
}
//////////////////END CODE FROM Roger Veciana's CLASS (assoc_array2xml) /////////////////////////////////


}//End Of Class


?>


a me funziona, fammi sapere ciao
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
scusa le utltme domande (solo 9^9)

1. posso fare dove mi serva la mapp includere il codice

PHP:
//ecc.......
<?
$map->addAddress('Via Frusa 22, Firenze');
//$map->addAddress('210 Doster Ave, Mooresville, NC 28115');
//$map->addAddress('300 Dingler Ave, Mooresville, NC 28115');
$map->showMap();
?>
//ecc.......

e posso sostituire addAdresse($indirizzo_cliente); //da db?, cioè al posto del nome la variabile che contiene l'indirizzo?

2. non vedo dove (c'è la possibilità?) settare le variabili di width e heigt in quanto altrimenti devo adattare le misure del <div> che contiene la mappa (come detto in prec post inclusa da file.txt e con dim fissate)

ciao e grazie
 

nicola.firenze

Nuovo Utente
14 Set 2008
6
0
0
Per quanto riguarda le dimensioni della mappa le puoi modificare a tuo piacimento attraverso le funzioni membro

$map->setWidth(500);
$map->setHeight(500);

al posto del 500, metti il valore che ti interessa
 

nicola.firenze

Nuovo Utente
14 Set 2008
6
0
0
per il db

per quanto riguarda il db, non ci sono problemi a patto che la stringa che passi alla finzione sia correttamente formattata.
 

LaKanka

Utente Attivo
29 Ago 2008
166
0
0
Ciao, ho provato ad inserire una mappa ma quando arrivo a scrivere all'interno della pag
PHP:
$map->setWidth(300);
$map->setHeight(300);
$map->addAddress('Via Frusa 22, Firenze');
$map->showMap();

mi blocca il layout....

Quale può essere il problema? eppure ho seguito le istruzioni passo per passo!!
 
Discussioni simili
Autore Titolo Forum Risposte Data
Tommy03 [PHP] Iframe Google Maps PHP 1
base90 [PHP] [HTML] Google Maps con due indirizzi PHP 12
L Google maps aggiunta makers da php Javascript 4
Sargon Google maps mysql php PHP 3
Sargon google maps java-xml-php-mysql Javascript 0
neo996sps Google maps + db mysql + php PHP 0
L Google chart php mysql PHP 2
R Tradurre stringhe con php e google translator PHP 4
ANDREA20 [PHP] Google PHP 1
andreas88 Da .htm a .php, perdo le mie posizioni su Google ricerca? SEO e Posizionamento 9
L [PHP] Inserire google recaptcha in uno form contatti PHP 1
G Google recaptcha in verify.php - dove inserire il codice PHP 1
S [PHP] Qualcuno utilizza i grafici Google charts? PHP 1
T PHP sync con gmail, rubrica google e calendario google PHP 0
neo996sps Inserire grafico google analytics in pagina PHP Google Analytics 0
G criptare ifarme di google fusion table in una pagina php PHP 7
Sargon google, php,API PHP 2
D Google Webmaster Tools Api in php Google Search Console 0
C script php per posizionamento su google PHP 0
M interfaccia php a google calendar PHP 16
neo996sps Google analitics in pagina PHP PHP 2
G Aprire Google con php PHP 5
U google in php PHP 0
F Cerco Hosting con VECCHIE versioni di php Hosting 0
Cosina Captcha php PHP 1
S passare un valore da un form a un file .php con metodo post PHP 4
N php msyql PHP 6
N php problemi a visualizzare video PHP 3
A menu a tendina php PHP 1
D protezione cartelle: blocco visualizzazione/scaricamento contenuto, ma abilitazione utilizzo dati da parte di file .php presenti sul sito Web Server 1
F Php date_diff PHP 1
K [PHP] Aggiungere caratteri ad una stringa in base alla lunghezza della stessa PHP 2
C Wp-admin a file php WordPress 5
Lino80 [Retribuito] Cerco programmatore php per modifica/inserimento funzione/valori da un plugin importer wordpress Offerte e Richieste di Lavoro e/o Collaborazione 0
csi Inviare file jpg in locale alla stampante con php PHP 0
M Passaggio variabili array php su un tasto jq PHP 3
E Php aggiornamento tabella PHP 9
G phpmailer e php 8.1 con estensione mysqli PHP 6
M Invio dati database via email php PHP 0
K [php] Problema con inner join PHP 4
K [php]form invio dati PHP 0
P Codifica caratteri speciali mysql php PHP 0
K [PHP] Problema con variabili concatenate. PHP 1
E Stampante termica escpos-php PHP 6
JeiMax Modifica codice php personalizzato PHP 2
G Come modificare un pdf in php PHP 1
U Link a doppio file PHP PHP 0
E PHP & jQuery PHP 8
N Passare array da php a javascript PHP 5
F Applicazione PHP/MySQL per prenotazioni: limitare il numero massimo di posti prenotabili PHP 20

Discussioni simili