We should have some method of display results on a map, and maybe allowing people to specify a location with the map.

Comments

billnbell’s picture

You can easily get the lat/long without getting a Google Maps dev key:


    // populate $value2 with any part of the address. Google is so good.
    // I use this to feed SOLR with the lat long from the 2nd input box 
    $value2 = "Denver, co";
    $search = sprintf("http://maps.google.com/maps/geo?output=csv&q=%s",urlencode($value2));
    $content = explode(",", file_get_contents("$search"));

    $lat = $content[2];
    $lon = $content[3];
ajevans85’s picture

I think the original issue was creating a new view of the search results... so instead of displaying a paginated list display a map with the POI marked on it.

I think billnbell'a above code is for getting the centre point to do a distance query. Idealy if we have a dependency allready on the Location module maybe we should use that as it has functionality to get the centrepoint from different data sources (google, yahoo i think, database).

billnbell’s picture

Yes it does, but I don't like loading data into mysql that is going to change constantly. Plus I don't have time to parse the human input. Google already did the work for you.

billnbell’s picture

Does anyone have a patch to att a block that will allow you to see the search results on the gmap?

mikejoconnor’s picture

I would love to see that. I don't know of anything that does that right now, however it should be relatively easy to do. I have a client that will sponsor the work, but not for a few weeks.

billnbell’s picture

Awesome. If you need some help let me know.

billnbell’s picture

Any movement on this?

ajevans85’s picture

Just going back to this

<?php
    // populate $value2 with any part of the address. Google is so good.
    // I use this to feed SOLR with the lat long from the 2nd input box
    $value2 = "Denver, co";
    $search = sprintf("http://maps.google.com/maps/geo?output=csv&q=%s",urlencode($value2));
    $content = explode(",", file_get_contents("$search"));

    $lat = $content[2];
    $lon = $content[3];
?>

I have just been using this concept to geocache some address I have, all was working until google locked me out with the below error:

We're sorry... ... but your query looks similar to automated requests from a computer viWe're sorry... ... but your query looks similar to automated requests from a computer virus or spyware application. To protect our users, we can't process your request right now. rus or spyware application. To protect our users, we can't process your request right now.

So it looks like a big no to use this approach.

On some good news (depending on how you look at it) having just split up with my girlfriend I should have some time to start working on this again.

billnbell’s picture

You can get a Google Maps API key and include it.

$request  = 'http://maps.google.com/maps/geo?';
  $request .= 'q='.$value2.'&';
  $request .= 'key=MY GOOGLE API KEY&';
  $request .= 'output=csv&';
  $request .= 'oe=utf8';

http://code.google.com/apis/maps/signup.html

See also: http://code.google.com/apis/maps/documentation/geocoding/

billnbell’s picture

If you are using this on your web site, you can use Javascript so that the request comes from the user's IP address. This is the approved approach from Google as well... Here is some sample code.


<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key=<your key>" type="text/javascript"></script>


<script type="text/javascript">

function showAddress(address) {
    if ((address.length==0) || (address==null)) {
      return true;
   }

	if (document.getElementById("latlong").value == 'notyet') {

		var geocoder = new GClientGeocoder();
   
		if (geocoder) {
			geocoder.getLatLng(
				address,   
				function(point) {
					if (!point) {
						alert(address + " is not found");
						return true;
					} else {
						var lat1 = point.lat();
						var lng1 = point.lng();
						document.getElementById("latlong").value = lat1 + ',' + lng1;
						var btn = document.getElementById('search_submit');
						btn.click();
					}
				}
			);
		}
		return false;
	}
	return true;
};


</script>	
<form id="search_frm" action="/searchads" onsubmit="return showAddress(this.where.value)">
							<label for="what">What?</label>
							<input type="text" id="search_term" name="search" maxlength="255" size="35" value=""/>
							<label for="where">Where?</label>
							<input type="hidden" id="latlong" name="latlong" value="notyet" />
							<input name="where" type="text" value="Denver, CO" />
</form>

Enjoy!