PRoblem with Google MAP and Hebrew

179 views
Skip to first unread message

Itzik Ventura

unread,
Feb 6, 2012, 11:01:47 AM2/6/12
to hit-php-june-2011
שלום חברים אולי מישהו נתקל בזה

שרון
אולי אתה נתקלת בזה כשקאת את קווי אורך ורוחב של האתרים?

אולי אתה נצקלת בבעיה דומה. אני מנסה מ-Php לגשת לשרת לעדכן קווי אורך
ורוחב מגוגל ואני משתמש בקוד הזה:
הבעיה היא שאני מקבל תוצאה שאם אני מריץ אותה ישירות ה-: אחרי ה- http
נעלמות אם אני מוסיף השורה עובדת טוב ומחזירה לי ערכים ב-Jason
זה הקוד:

function GetGoogle_Lon_Lat($siteAdd,$siteAddNo,$siteCity)
{
$searchSite="http://www.maps.google.com/maps/api/geocode/json?
address=".$siteAdd."+".$siteAddNo."+".$siteCity."+IL&sensor=false";
printf ($searchSite);
$geocode=file_get_contents($searchSite);
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;
echo "<br>Latitude : ".$lat;
echo "<br>Longitude : ".$long;
}

זה מה שאני מקבל

http://www.maps.google.com/maps/api/geocode/json?address=המדע+2+יוקנעם
+IL&sensor=false

אם אני מכניס ערכים באנגלית זה עובד טוב
אם ערכים בעברית זה לא עובד ואם אני מעתיק את השורה שהודפסה ומריץ אותה
ישירות בדפדפן ה-: מה-http נעלמים
יש לך רעיון?
נתקלת בזה?

תודה
איציק

Sharon lavie

unread,
Feb 6, 2012, 12:48:03 PM2/6/12
to hit-php-june-2011
היי איציק, תנסה להיעזר בקוד הבא:
אני חושב שהפקודה המרכזית שחסרה לך היא URLENCODE, זו הדרך לטפל בעברית
המועברת בתוך שורת ה-URL.
אם אתה לא מסתדר, צור איתי קשר טלפוני ב-0542477232.

בהצלחה.
שרון.

$businessAddress = $address.' '.$city;
//encode the hebrew business address to url value
$businessAddress = urlencode($businessAddress);
//get the json from google
$url = file_get_contents('http://maps.googleapis.com/maps/api/geocode/
json?address='.$businessAddress.'&sensor=false');
//make the json an array
$json = json_decode($url,true);
//assing the latitude and longtitude to variables
$lat = $json['results'][0]['geometry']['location']['lat'];
$lon = $json['results'][0]['geometry']['location']['lng'];

Itzik Ventura

unread,
Feb 7, 2012, 1:57:04 AM2/7/12
to hit-php-...@googlegroups.com
היי שרון
עובד תודה,
איציק

בתאריך 6 בפברואר 2012 19:48, מאת Sharon lavie <sharon...@gmail.com>:



--
בברכה
איציק ונטורה- 052-8367444
בית-צימר.com
http://www.bayt-zimmer.co.il


Alon b

unread,
Jan 20, 2013, 4:45:01 AM1/20/13
to hit-php-...@googlegroups.com
שלום שרון/איציק

העתקתי את הקוד שרשמת פה שניכם אך לא הצלחתי

האם תוכלו לפרסם בבקשה את הקוד המלא שהצליח לעבוד לכם עם כתובות בעברית

כלומר שהליק הבא יעבוד עם שירות geocode:
http://maps.google.com/maps/api/geocode/json?address=המדע+2+יוקנעם&sensor=false"

הנה הקוד:

תודה רבה
<?php

$siteAdd="סולד"
$siteAddNo="10"
$siteCity="הרצליה"
        $searchSite="http://www.maps.google.com/maps/api/geocode/json?address=".$siteAdd."+".$siteAddNo."+".$siteCity."+IL&sensor=false"
                printf ($searchSite);
                $geocode=file_get_contents($searchSite);
        $output= json_decode($geocode);
        $lat = $output->results[0]->geometry->location->lat;
        $long = $output->results[0]->geometry->location->lng;
        echo "<br>Latitude : ".$lat;
        echo "<br>Longitude : ".$long;

?>

Sharon lavie

unread,
Jan 20, 2013, 8:32:59 AM1/20/13
to hit-php-...@googlegroups.com
היי אלון,

התשובה היא פשוטה,
חסר לך מה שחסר היה לאיציק.
אתה צריך לעטוף את הכתובת בעברית בפקודה URLENCODE, הפקודה הזו מעבירה את העברית לפורמט שה-API יודע לעבוד איתו.
ז"א שאת הסטרינג שאתה מייצר עבור הכתובת מעבר כפרמטר ל-API אתה צריך להעביר דרך urlencode.
בדוגמה שלך תרשום:
$siteAdd="סולד";
$siteAddNo="10";
$siteCity="הרצליה";
$encoded_address = urlencode($siteAdd." ".$siteAddNo." ".$siteCity);
        $searchSite="http://www.maps.google.com/maps/api/geocode/json?address=$encoded_address+IL&sensor=false"

בהצלחה.

שרון.

Alon b

unread,
Jan 20, 2013, 3:13:30 PM1/20/13
to hit-php-...@googlegroups.com
היי  שרון
עשיתי מה שרשמת אבל אני לא יודע למה לא עובד.
אני מקבל שגיאת שרת כאשר אני מריץ את הקוד הבא (באנגלית עובד טוב)
אשמח לעזרה
תודה
<?php
 
function lookup($string){
 
   $string = str_replace (" ", "+", urlencode($string));
   $details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$string."&sensor=false";
 
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $details_url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   $response = json_decode(curl_exec($ch), true);
 
   // If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST
   if ($response['status'] != 'OK') {
    return null;
   }
 
   print_r($response);
   $geometry = $response['results'][0]['geometry'];
 
    $longitude = $geometry['location']['lat'];
    $latitude = $geometry['location']['lng'];
 
    $array = array(
        'latitude' => $geometry['location']['lng'],
        'longitude' => $geometry['location']['lat'],
        'location_type' => $geometry['location_type'],
    );
 
    return $array;
 
}
 
$city = 'הנרייטה סולד 10, כפר סבא';
$encoded_address =urlencode($city) 
$array = lookup($city);
print_r($array);
 
?>

בתאריך יום ראשון, 20 בינואר 2013 15:32:59 UTC+2, מאת Sharon lavie:

Itzik Ventura

unread,
Jan 20, 2013, 4:02:03 PM1/20/13
to hit-php-...@googlegroups.com
היי אלון
אני מדביק קוד איתו אני עובד
HTML:

<tr><td>
<form name="GetSiteLongitudeLatitude">
<p>Type site address and get site Longitude&Latitude.<br>or type site Longitude&Latitude and get Mag</p>
רחוב האתר:/Long (32)<input type="text" name="siteAdd" /><br>
מספר רחוב:/Lat (35)<input type="text" name="siteAddNo" /><br>
עיר  האתר :<input type="text" name="siteCity" /><br>
<input type="button" value='getSite_Lon&Lat' onClick="getSiteLonLat()"/>
<input type="button" value='getSiteMap' onClick="getSiteMap()"/>
</form>
</td></tr>


JS:
function getSiteLonLat() // return site Long&Lat
{
//alert ("רחוב "+document.GetSiteLongitudeLatitude.siteAdd.value+". מספר="+document.GetSiteLongitudeLatitude.siteAddNo.value+". עיר "+document.GetSiteLongitudeLatitude.siteCity.value);
$.ajax({
url: mySite+"func=getGoogleLongLat",
data: "address=" + document.GetSiteLongitudeLatitude.siteAdd.value + "& addressNo=" + document.GetSiteLongitudeLatitude.siteAddNo.value + "& city=" + document.GetSiteLongitudeLatitude.siteCity.value,
success: function (result) {
// alert(result); // testing - display the results
$("#coupons").html(result);
$("#coupons").listview("refresh");
}
})
}

PHP:
function getGoogleLongLat($siteAdd,$siteAddNo,$siteCity)
{
$businessAddress = $siteAdd.' '.$siteAddNo.' '.$siteCity;
    //encode the hebrew business address to url value
$businessAddress = urlencode($businessAddress);
    //get the json from google
    //make the json an array
$json = json_decode($url,true);
    //assing the latitude and longtitude to variables
$lat = $json['results'][0]['geometry']['location']['lat'];
$lon = $json['results'][0]['geometry']['location']['lng'];
print"<br><input type='button' value='הצג מפת אתר' onClick='getSiteMapByLongLat(".$lon.",".$lat.")'/>";
echo "<br>Latitude : ".$lat;
echo "<br>Longitude : ".$lon;
echo "<br>".$lat.",".$lon;
}


בתאריך 20 בינואר 2013 22:13, מאת Alon b <alon...@gmail.com>:



--
בברכה
איציק ונטורה
לטייל בצפון עם GoNorth
צימר בית בהר

Sharon lavie

unread,
Jan 20, 2013, 6:25:05 PM1/20/13
to hit-php-...@googlegroups.com
היי אלון,

נסה להשתמש במה שאיציק כתב,
בכל מקרה לא הבנתי מדוע השתמשת בפונקציה curl_setopt.

On Monday, February 6, 2012 6:01:47 PM UTC+2, Itzik Ventura wrote:

Alon b

unread,
Jan 21, 2013, 3:11:14 AM1/21/13
to hit-php-...@googlegroups.com
היי תודה על הסיוע,
ניסיתי לקחת רק את הקטע של PHP
יש לי אותה בעיה: כתובות באנגלית עובדות טוב- אך בעברית (כמו הקוד המצורף) לא עובד לי
<?PHP
$businessAddress = "הברזל+34+רעננה";
    //encode the hebrew business address to url value
$businessAddress = urlencode($businessAddress);
    //get the json from google
$json = json_decode($url,true);
    //assing the latitude and longtitude to variables
$lat = $json['results'][0]['geometry']['location']['lat'];
$lon = $json['results'][0]['geometry']['location']['lng'];
echo "<br>Latitude : ".$lat;
echo "<br>Longitude : ".$lon;

?>

בתאריך יום שני, 21 בינואר 2013 01:25:05 UTC+2, מאת Sharon lavie:

Sharon lavie

unread,
Jan 22, 2013, 11:08:59 AM1/22/13
to hit-php-...@googlegroups.com
אם אתה כותב את העברית בתוך הקוד, יכולה להיות לך בעיה, כי זה תלוי באיך שסביבת הפיתוח שלך שומרת את הטקסט, ייתכן והיא לא עובדת ב-UNICODE.
תנסה לקבל את הכתובת מהמשתמש, ז"א - צור טופס שבו המשתמש מכניס את הכתובת, סתם טופס של שדה אחד וכפתור SUBMIT ותראה אם זה עוזר.

שרון.

Alon b

unread,
Jan 22, 2013, 12:08:52 PM1/22/13
to hit-php-...@googlegroups.com
הי שרון
תודה
יצרתי טופס שמעביר את הכתובת מהמשתמש
אני מקבל לאחר פעולת encoding את הסטרינג הבא: 

http://maps.googleapis.com/maps/api/geocode/json?address=%E4%E1%F8%E6%EC+34+%FA%EC+%E0%E1%E9%E1&sensor=false

לעומת זאת כאשר אני מכניס את הכתובת ישירות בדפדפן אני מקבל את הסטרינג הבא (לכתובת העברית) וזה עובד טוב:

http://maps.googleapis.com/maps/api/geocode/json address=%D7%94%D7%91%D7%96%D7%A8%D7%9C+34+%D7%AA%D7%9C%20%D7%90%D7%91%D7%99%D7%91&sensor=false
אפשר לראות שזה שתי תוצאות שונות (מסומן באדום)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
בתאריך יום שלישי, 22 בינואר 2013 18:08:59 UTC+2, מאת Sharon lavie:

Sharon lavie

unread,
Jan 25, 2013, 3:21:33 AM1/25/13
to hit-php-...@googlegroups.com
היי, 

מוזר.
שלח לי את קטע הקוד שכתבת ואני אנסה אותו אצלי.

Alon b

unread,
Jan 28, 2013, 5:33:00 PM1/28/13
to hit-php-...@googlegroups.com
זהו סוף סוף הצלחתי

הייתי צריך לשמור את הדף כ UTF-8
עכשיו עובד מעולה

תודה שרון 

בתאריך יום שישי, 25 בינואר 2013 10:21:33 UTC+2, מאת Sharon lavie:
Reply all
Reply to author
Forward
0 new messages