-1

I have used the tutorial here http://tech.cibul.net/geocode-with-google-maps-api-v3/ to create a page with map and draggable marker to display address and lat/long.

Demo - http://www.calcunation.com/testgeo.php

How do I captured those results and put them into a php variable so I can insert into a mysql database?

I'm relatively new to Java, and fairly comfortable with PHP.

Kara
  • 6,115
  • 16
  • 50
  • 57

2 Answers2

0

AJAX would be the cleanest from a user perspective. I'd use jquery $.post to do it http://api.jquery.com/jQuery.post/.

CraigH
  • 13
  • 3
0

Are you trying to split out the address components?

Like street, city, state, zip....

If so...you'll want to look at the geocoded result, and parse through the array of address types that it returns.

Here is some quick sample code you can use...

//Startup a new geocode instance

var geocoder = new google.maps.Geocoder();

//event.latLng is a latLng object passed into the geocode function to get 
your addy results

geocoder.geocode({'location': event.latLng}, function(results, status) {

//Show the results here
console.log(results);

if (status == google.maps.GeocoderStatus.OK) {

    var addressResults = results[0].address_components;
    var address1 = "";
    var address2 = "";
    var city = "";
    var state = "";
    var zipCode = "";

    for(var i = 0; i < addressResults.length; i++){

        for(var j = 0; j < addressResults[i].types.length; j++){
            if(addressResults[i].types[j] == 'street_number'){
                address1 = addressResults[i].long_name;
                break;
            }

            if(addressResults[i].types[j] == 'route'){
                address1 += " " + addressResults[i].long_name;
                break;
            }

            if(addressResults[i].types[j] == 'subpremise'){
                address2 = addressResults[i].long_name;
                break;
            }

            if(addressResults[i].types[j] == 'locality'){
                city = addressResults[i].long_name;
                break;
            }

            if(addressResults[i].types[j] == 'administrative_area_level_1'){
                state = addressResults[i].short_name;
                break;
            }

            if(addressResults[i].types[j] == 'postal_code'){
                zipCode = addressResults[i].long_name;
                break;
            }
        }
    }

    //Do ajax post to your form here with the data you just parsed out
}
});
aamir
  • 23
  • 7
Kevin Mansel
  • 2,351
  • 1
  • 16
  • 15