Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

I put together this php to geocode an address in filemaker. I am new to PHP and this is the first PHP script I have ever written. I got most of the code from Begining Google Maps Applications with PHP and Ajax (great book). This was done using the Testbed v2 file. I created new fields, address, city, state, and zip to pass to the script.

header('content-type:text/plain;');



$api_key = "...enter key here...";



// First we store our FileMaker expression

$address= fm_evaluate('GetField ( "address" )');

$city = fm_evaluate('GetField( "city" )');

$state = fm_evaluate('GetField( "state" )');

$zip = fm_evaluate('GetField( "zip" )');



// Create a CURL object for later use

$ch = curl_init();

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

 

// Construct the request string

$url = "http://maps.google.com/maps/geo?output=xml&key=$api_key&q=";

$url .= urlencode($address);

$url .= "&city=".urlencode($city);

$url .= "&state=".$state;

$url .= "&zip=".$zip;



$url2 = "http://maps.google.com/maps/geo?output=xml&key=$api_key&q=".$zip;



// Query Geocoder.ca for the lat/long

curl_setopt($ch, CURLOPT_URL, $url);

$response = curl_exec($ch);

 



	// Use SimpleXML to parse our answer into something we can use

	$googleresult = simplexml_load_string($response);

	//echo "Status: ".$googleresult->Response->Status->code."n";

	if ($googleresult->Response->Status->code != 200 || $googleresult->Response->Placemark->AddressDetails->Country->AdministrativeArea->SubAdministrativeArea->Locality->PostalCode->PostalCodeNumber != $zip){

	curl_setopt($ch, CURLOPT_URL, $url2);

	$response = curl_exec($ch);

		$googleresult = simplexml_load_string($response);

		

		echo "Results based on zip coden";

		foreach ($googleresult->Response as $response){

			foreach ($response->Placemark as $place){

			list($longitude, $latitude) = split(",",$place->Point->coordinates);

			//echo "Result Address: ".$place->address."n";

			echo "$latituden";

			echo "$longituden";

		}

	 }

			

	}

		

	else foreach ($googleresult->Response as $response){

		foreach ($response->Placemark as $place){

		list($longitude, $latitude) = split(",",$place->Point->coordinates);

			//echo "Result Address: ".$place->address."n";

			echo "Results based on full addressn";

			echo "$latituden";

			echo "$longituden";



		} // for each placemark		

	} //for Google result

 

// Close the CURL file and destroy the object

curl_close($ch);

The script will take the address and geocode it, it then checks the returned zip code to insure it matches the original zip coe, if it doesn't it geocodes againonly passing the zip code in the url. I found this necessay because if I passed in a RR Box address in illinois, google was returningcooridinates for California. This doesn't work real well when trying to plot points on a map. So basically if google cannot find the exact address, the script retrieves the coordinates for the zip code only.

Any suggestions on an easier or more elegant way of doing this would be greatly appreciated, as I am just learning PHP.

Hope his helps someone out :)

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.