I've been playing with the GMap module for the first time, and have reviewed several how-to videos.

I'm able to allow a user to specify the location on the map (by clicking).

How can I get the address/city/state/zip to calculate the latitude and longitude automatically?

Here's the text that appears in the "Location" section of Content, Edit:

If you wish to supply your own latitude and longitude, you may enter them above. If you leave these fields blank, the system will attempt to determine a latitude and longitude for you from the entered address. To have the system recalculate your location from the address, for example if you change the address, delete the values for these fields.

You may set the location by clicking on the map, or dragging the location marker. To clear the location and cause it to be recalculated, click on the marker.

Thanks for any clarification that you can provide.

Vince Lackner

Comments

hutch’s picture

Ensure that you have enabled geocoding and have the zipcodes table setup done. Using Location module that is

vince@lacknergroup.com’s picture

Thanks, Hutch. I did figure out late last night that I needed to install the GeoCode module.

I didn't have to do anything special with zip codes. Just curious, where would I do the zip code table setup?

Best,
Vince

ice5nake’s picture

Like hutch mentions, if you're using the location module you just need to configure your location module to do geocoding for your region. For example I enabled geocoding for the United States.

If you're not using the location module you probably need to use the Geocode module that VinceL mentions.

arski’s picture

works perfectly for me too after having enabled the geolocation stuff. nice nice :)

johnv’s picture

Status: Active » Closed (fixed)
sumitmadan’s picture

Status: Closed (fixed) » Active

Not working after enabling GeoCode module also. I selected the country in geocoding option. Am i missing something?

planctus’s picture

Not working for me too. Don't know when it stopped working, i noticed this only recently, i've updated the module to the 6.x-2.0-beta5 but that didn't fix the problem.
I'm using a location field and geocoding options are correctly set.
Thanks,
Da.

sumitmadan’s picture

I solved this using custom code in hook_nodeapi.

if(!empty($node->field_event_location) && ( $node->field_event_location[0]['locpick']['user_latitude'] == "" || $node->field_event_location[0]['locpick']['user_longitude'] == "" || round($node->field_event_location[0]['locpick']['user_latitude']) == 0 || round($node->field_event_location[0]['locpick']['user_longitude']) == 0 )) {
	$address = $node->field_event_location[0]['name'].", ".$node->field_event_location[0]['street'].", ".$node->field_event_location[0]['additional'].", ".$node->field_event_location[0]['city'].", ".$node->field_event_location[0]['province'].", ".$node->field_event_location[0]['country'];
	$prepAddr = str_replace(' ','+',$address);
	$geocode=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
	$output= json_decode($geocode);
	if(!empty($output->results)) {
		$latitude = $output->results[0]->geometry->location->lat;
		$longitude = $output->results[0]->geometry->location->lng;
		$node->field_event_location[0]['latitude'] = $latitude;
		$node->field_event_location[0]['longitude'] = $longitude;
		$node->field_event_location[0]['locpick']['user_latitude'] = $latitude;
		$node->field_event_location[0]['locpick']['user_longitude'] = $longitude;
		node_save($node);
	}
}
planctus’s picture

Sorry, forget my comment..it is woking now.
Da.

jkingsnorth’s picture

Issue summary: View changes
Status: Active » Fixed

This issue seems to have been fixed, marking as such.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

bisw’s picture

Thanks @sumit.. saved lot of time..:)