Parsing street addresses in Ruby

前端 未结 5 1750
萌比男神i
萌比男神i 2021-02-09 18:08

I am processing addresses into their respective field format for the database. I can get the house number out and the street type but trying to determine best method to get the

5条回答
  •  北海茫月
    2021-02-09 18:31

    I currently just pass whatever I am given to googlemaps and have them send back a formatted street address that is very easy to parse.

    function addressReview(addressInput) {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    geocoder.geocode( { 'address': addressInput}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      if (results[0]) {
        var addr = results[0].formatted_address;
        var latTi = results[0].geometry.location.lat();
        var lonGi = results[0].geometry.location.lng();
        $.post('/welcome/gcode',{ add: addr , la: latTi , lo: lonGi });
        $('#cust_addy').val(addr);
      } else {
        $('#cust_addy').attr("placeholder",'Cannnot determine location');
      }
    } else {
      $('#cust_addy').attr("placeholder",'Cannnot determine location');
    }
    });
    }
    

    After that, I just split it up in ruby. with .split(', ') and .split(' ')

提交回复
热议问题