I am creating a website for a magazine which has a page devoted to events (such as County Shows etc.) This page has an interactive map at the top (built with google maps), and then a section with the different events and their details in a 3col grid.
My boss wanted to have it so that when the website owners (we'll refer to them as the editor) are adding the event, it is possible for them to add the address of the event. When the editor saves the event, it then geocodes the address, and saves the lat&lng into their own hidden input fields.
There is then a loop on the Events page within the Google Maps syntax to create markers for each event using their LatLng.
I have the page created with the map but I do not know how to go about geocoding the address in the back end.
I do not mind whether or not the geocoding is done automatically when saving the post, or if it is manually converted through clicking a button. I just need a way to save the LatLng so I can call it from the loop.
So how can I do this? I understand I'm going to need some jQuery for the AJAX request, but which file should this go in? (the geocode.php
Code time!
Geocode.php:
$result = json_decode(file_get_contents($geoCodeURL), true);
echo $result['results'][0]['geometry']['location']['lat'];
echo ',';
echo $result['results'][0]['geometry']['location']['lng'];
Yeah... That's all I got.
Snippet of Functions.php
<td>
<form class="geocode" action="<?php bloginfo('template_url');?>/geocode.php" method="post">
<input type="text" name="addr" />
<input type="submit" value="" />
</form>
<input type="text" value="" name="eventLatLng" class="latlng" />
</td>
P.S. I'm very sorry if this is unclear, I've never worked with AJAX and I'm a bit confused as to how to explain it, so sorry if I wasn't much help.