[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Google map Question

Posted on 2010-01-03
13
Medium Priority
?
422 Views
Last Modified: 2013-12-12
Hi,

I have a simple google map application to find the coordinates when typing the address in a text field.

Its working well in most of the cases.

But I am facing problem that when i type 'net use' in the text field , its not giving the coordinates ( address is not found.) I tried the 'net use' address in the "maps.google.be" site and I got the addresses.

What might be the problem?

I thought that may be the space used between the 'net' and 'use' words, but I got info about the place "Den haag" in my application as well as in the google site directly.

So please help me.

Thanks in advance.
google.txt
0
Comment
Question by:shobinsun
  • 6
  • 6
13 Comments
 
LVL 14

Expert Comment

by:profya
ID: 26165372
I don't think there is a problem with that, your address 'net use' returns 602 status code, the same as if you enter 'dsadasdsadasdasdasdasda', it means that it does not find it. You can test it using Google sample at: http/code.google.com/apis/maps/documentation/examples/geocoding-simple.html
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26165467
I think your problem is that Belgium does not exist.  See here:
http://zapatopi.net/belgium/

;-)

Now having said that, what address or geocode did you expect "net use" to produce?
0
 
LVL 14

Author Comment

by:shobinsun
ID: 26165916
Hi ,

Thanks for your quick reply.

I expect the solution that is given by:

http://maps.google.be/

when entering "net use".

Here I am attaching the screen shot I am getting with google map directly and what i am expecting.

Thanks.

Screenshot.png
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26165935
This is interesting.  I tried URL http://maps.google.be/maps and entered "net use" - this is what it gave back for the link, and it is faithful to the locations near Antwerp.

http://maps.google.be/maps?f=q&source=s_q&hl=nl&geocode=&q=net+use&sll=50.805935,4.432983&sspn=5.075643,14.666748&ie=UTF8&hq=net+use&hnear=&z=12
0
 
LVL 14

Author Comment

by:shobinsun
ID: 26169193
Hi,

This is an application on the web for getting latitude and longitude values:

http://seifi.org/wp-content/uploads/2005/04/googlemapsll.php?q=net+use

When typing "net use", I got the values.

And tried this:

http://maps.google.be/maps/geo?q=net%20use

Error code getting.

So what to do?

Please give me some advice.

Thanks.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 26170912
I tried this:
http://seifi.org/wp-content/uploads/2005/04/googlemapsll.php?q=net+use+belgium
and got
Latitude: 50.958651000000003
Longitude: 4.1947539999999996

The I tried this:
http://seifi.org/wp-content/uploads/2005/04/googlemapsll.php?q=net+use
and got
Latitude: -6.5782230000000004
Longitude: -38.843145

Very different answers!

This gave me a map in South America:
http://maps.google.be/maps?f=q&source=s_q&hl=enl&q=net+use

And this gave me a map in Belgium:
http://maps.google.be/maps?f=q&source=s_q&hl=enl&q=net+use+belgium

My guess is that Google is being somewhat creative as it tries to interpret the address, "net use" - I have found this in other Google geocoder applications - if you give it a "bad" address, it will try to find something that more-or-less matches the character string.

I found the Yahoo geocoder to be more dependable about rejecting invalid addresses.  I am not sure what your specific application needs are, but you are welcome to try my geocoder class.  Source code attached.  Best, ~Ray
<?php // RAY_class_SimpleGeoCoder.php
error_reporting(E_ALL);

// API KEYS, ETC., IF REQUIRED
// require_once('commonConfig.php');


// PUT UP A FORM TO RECEIVE THE ADDRESS INFORMATION
if (empty($_GET))
{    ?>
<html><head><title>Yahoo/Google SimpleGeoCoder Demo</title></head>
<body>
<form method="get">
Addr: <input type="text" name="a" autocomplete="off" />
City: <input type="text" name="c" autocomplete="off" />
ST:   <input type="text" name="s" autocomplete="off" size="2" />
Zip:  <input type="text" name="z" autocomplete="off" size="8" />
<input type="submit" name="_go" value="go" />
</form>
</body>
</html>
<?php
    die();
}


// A FREEFORM LOCATION STATEMENT IS OPTIONAL - GET ADDRESS, CITY, STATE, ZIP FROM THE URL
$location = '';
if ($_GET["a"] != '') { $location .= $_GET["a"] . ' '; }
if ($_GET["c"] != '') { $location .= $_GET["c"] . ' '; }
if ($_GET["s"] != '') { $location .= $_GET["s"] . ' '; }
if ($_GET["z"] != '') { $location .= $_GET["a"] . ' '; }
$location = trim($location);


// PREPARE THE GEOCODER
$demo          = new SimpleGeoCoder;
$demo->address = $_GET["a"];
$demo->city    = $_GET["c"];
$demo->state   = $_GET["s"];
$demo->zip     = $_GET["z"];

// TEST THE YAHOO! GEOCODER
$demo->geocodeYahoo();
echo "<pre>\n\nYAHOO! ";
print_rr($demo);
echo "</pre>\n";

// TEST THE GOOGLE GEOCODER
$demo->geocodeGoogle();
echo "<pre>\n\nGOOGLE ";
print_rr($demo);
echo "</pre>\n";


// ALL DONE
die();



// SIMPLE GEOCODER CLASS
class SimpleGeoCoder
{

// DECLARE THE INPUT DATA
    public $location; // USE THIS FOR A FREEFORM QUERY, OR USE THE PARTS
    public $address;
    public $city;
    public $state;
    public $zip;

// DECLARE THE WORKING DATA
    private $precis; // TEXTUAL PRECISION FROM YAHOO
    private $yfp, $yahooUrl,  $yahooResponse,  $ydata;
    private $gfp, $googleUrl, $googleResponse, $gdata;

// DECLARE THE OUTPUT DATA
    public $latitude;
    public $longitude;
    public $precision;
    public $warning;
    public $geocoder;

// DECLARE THE CONSTRUCTOR
    public function __construct()
    {
        $this->latitude  = 0.0;
        $this->longitude = 0.0;
        $this->precision = FALSE; // WANT A VALUE OF 5 OR HIGHER, HIGHER IS BETTER
        $this->warning   = '';
        $this->geocoder  = '';
        unset($this->precis);
    }

// DECLARE THE DATA-CLEANUP
    private function _cleanup($str)
    {
        $str = ereg_replace('[^\' a-zA-Z0-9&!#$%()"+:?/@,_\.\-]', '', $str);
        return trim(ereg_replace(' +', ' ', $str));
    }

// DECLARE THE YAHOO! VERSION OF THE WORKHORSE
    public function geocodeYahoo()
    {
        $this->geocoder = 'Yahoo!';
        $yahooUrl       = "http://local.yahooapis.com/MapsService/V1/geocode?&appid=" . YAHOO_API;
        if ($this->location != '') // YOU CAN ASK FOR A FREEFORM QUERY
        {
            $yahooUrl .= "&location=" . urlencode($this->_cleanup($this->location));
        }
        else // YOU CAN ASK FOR INDIVIDUAL PIECES OF AN ADDRESS
        {
            $yahooUrl .= "&street=" . urlencode($this->_cleanup($this->address));
            $yahooUrl .= "&city="   . urlencode($this->_cleanup($this->city));
            $yahooUrl .= "&state="  . urlencode($this->_cleanup($this->state));
            $yahooUrl .= "&zip="    . urlencode($this->_cleanup($this->zip));
        }

// EXECUTE YAHOO GEOCODER QUERY
// NOTE - USE ERROR SUPPRESSION OR IT WILL BARF UP THE YAHOO API - ON FAILURE RETURNS HTTP 400 BAD REQUEST
        if ($yfp = @fopen($yahooUrl, 'r'))
        {
            $yahooResponse = '';
            while (!feof($yfp)) { $yahooResponse .= fgets($yfp); }
            fclose($yfp);
        }
        else
        {
            return FALSE;
        }

// EXAMINE THE RESULT
        if ($yahooResponse != '') // NOT EMPTY, WE GOT DATA
        {
            $ydata    = new SimpleXMLElement($yahooResponse);

// CHECK FOR ANY ERROR MESSAGE, IF NONE, EXTRACT THE DATA POINTS
            $yerror    = $ydata->Message;
            if ($yerror == '')
            {
                $this->precis    = (string)$ydata->Result["precision"];
                $this->warning   = (string)$ydata->Result["warning"];
                $this->latitude  = (string)$ydata->Result->Latitude;
                $this->longitude = (string)$ydata->Result->Longitude;

// THESE STATEMENTS CAN BE USED TO RETURN NORMALIZED ADDRESS
                $this->address   = (string)$ydata->Result->Address;
                $this->city      = (string)$ydata->Result->City;
                $this->state     = (string)$ydata->Result->State;
                $this->zip       = (string)$ydata->Result->Zip;

// SET PRECISION TO A NUMBER VALUE
                if ($this->precis == 'zip')     { $this->precision = "5"; }
                if ($this->precis == 'street')  { $this->precision = "6"; }
                if ($this->precis == 'address') { $this->precision = "8"; }
            }
            else
            {
                return FALSE;
            }
        }
        else  // NO RESULT - SOMETHING IS SICK AT YAHOO
        {
            return FALSE;
        }
        return TRUE;
    } // END function geocodeYahoo



// DECLARE THE GOOGLE VERSION OF THE WORKHORSE
    public function geocodeGoogle()
    {
        $this->geocoder = 'Google';
        $googleUrl      = "http://maps.google.com/maps/geo?key=" . GOOGLE_API . "&output=csv";

        if ($this->location != '') // YOU CAN ASK FOR A FREEFORM QUERY
        {
            $googleUrl .= "&q=" . urlencode($this->_cleanup($this->location));
        }
        else // YOU CAN ASK FOR INDIVIDUAL PIECES OF AN ADDRESS
        {
            $googleUrl .= "&q="
                       . urlencode(trim(
                         $this->_cleanup($this->address) . ' '
                       . $this->_cleanup($this->city)    . ' '
                       . $this->_cleanup($this->state)   . ' '
                       . $this->_cleanup($this->zip)
                       ));
        }

// EXECUTE GOOGLE GEOCODER QUERY
        if ($gfp = @fopen($googleUrl, 'r'))
        {
            $googleResponse = '';
            while (!feof($gfp)) { $googleResponse .= fgets($gfp); }
            fclose($gfp);
        }
        else
        {
            return FALSE;
        }

// EXTRACT THE DATA
        $gdata    = explode(',',$googleResponse);
        if ($gdata[0] != '200') // RESPONSE CODE SHOULD BE '200' -- IF 602 - BAD ZIP CODE OR UNUSABLE ADDRESS
        {
            return FALSE;
        }
        $this->precision = $gdata[1]; // GEOCODE ACCURACY - ZIP CODE = 5, HIGHER NUMBERS ARE BETTER
        $this->latitude  = $gdata[2];
        $this->longitude = $gdata[3];
        return TRUE;
    } // END function geocodeGoogle
} // END class SimpleGeocoder



// A QUICK AND DIRTY FUNCTION TO MAKE THE OUTPUT SHOW THE PUBLIC INFORMATION ONLY
function print_rr($thing)
{
    $str = print_r($thing, TRUE);
    $arr = explode("\n", $str);
    $num = count($arr) -1;
    foreach ($arr as $ptr => $txt)
    {
        if (preg_match('/:private]/', $txt)) { unset($arr[$ptr]); }
    }
    echo implode("\n", $arr);
}

Open in new window

0
 
LVL 14

Author Comment

by:shobinsun
ID: 26177582
Hi,

Thanks for your reply and code. I tried your code and I got the result for "net use" as:

GOOGLE SimpleGeoCoder Object
(
    [location] =>
    [address] =>
    [city] => Net, Hindoli 323023
    [state] => India
    [zip] =>
    [yfp:private] =>
    [yahooUrl:private] =>
    [yahooResponse:private] =>
    [ydata:private] =>
    [gfp:private] =>
    [googleUrl:private] =>
    [googleResponse:private] =>
    [gdata:private] =>
    [latitude] => 21.0596718
    [longitude] => 73.0677295
    [precision] => 6
    [warning] =>
    [geocoder] => Google
    [precis:private] => zip
)


Its not the address what I expected.

And also I created a new entry ("zzzzzzzz")in google map and tried to get the geocode values via :

http://maps.google.com/maps/geo?q=zzzzzzzz

and getting the result as:

{
  "name": "zzzzzzzz",
  "Status": {
    "code": 602,
    "request": "geocode"
  }
}


So I think when creating the locations in the google map, its not creating the geocode values.

Then how can we create that?

Any idea about that?

Very interesting !!

Thanks.

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26181117
"And also I created a new entry ("zzzzzzzz")in google map and tried to get the geocode... So I think when creating the locations in the google map, its not creating the geocode values."

Not sure I understand.  How would Google come to understand that this had meaning as an address?
http://maps.google.com/maps/geo?q=zzzzzzzz
0
 
LVL 14

Author Comment

by:shobinsun
ID: 26182406
Hi,

Can you create  a new location with a valid address in the google map and try to get the geocode values, please.

I created "zzzzzzzz" named location ad address is : zzzzzz xxxxxx yyyyyy zzzzzz xxxxxx yyyyyy

But when i searched in the google maps, it gives me the result .

See the screen shot attached.

Then Why didnt get the geocode values?



Screenshot-2.png
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26182500
Check the fields that are shown in the red circle.  This is where you may be able to find the LAT/LON pair.
shobinsun.png
0
 
LVL 14

Author Comment

by:shobinsun
ID: 26187503
HI,

I can see the LAT and LONG values when mouse over the " Link ".

But How can we get the values using php code?

Can you give me a simple example?

Thanks.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 26190840
I'm not understanding something here.  Did you create the pointer that we see on the map pictures?  If so, wouldn't you know the LAT/LON pair?  It seems to me that getting the geocode data from Google is backwards - you would be telling Google the LAT/LON pair, right?
0
 
LVL 14

Author Closing Comment

by:shobinsun
ID: 31672096
Thank you very much..!!!!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month17 days, 22 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question