Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
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];
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).
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.
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.
<?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.
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&v=2&sensor=true&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>
Comments
Comment #1
billnbell commentedYou can easily get the lat/long without getting a Google Maps dev key:
Comment #2
ajevans85 commentedI 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).
Comment #3
billnbell commentedYes 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.
Comment #4
billnbell commentedDoes anyone have a patch to att a block that will allow you to see the search results on the gmap?
Comment #5
mikejoconnor commentedI 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.
Comment #6
billnbell commentedAwesome. If you need some help let me know.
Comment #7
billnbell commentedAny movement on this?
Comment #8
ajevans85 commentedJust going back to this
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.
Comment #9
billnbell commentedYou can get a Google Maps API key and include it.
http://code.google.com/apis/maps/signup.html
See also: http://code.google.com/apis/maps/documentation/geocoding/
Comment #10
billnbell commentedIf 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.
Enjoy!