1

I'm using this jQuery script:

http://ubilabs.github.io/geocomplete/

I read the documentation but it's quite minimal. There are links to the original API but the syntax is different and I can't make something out of it.

I would like to know how to retrieve the street_number as a result.

This is how I did to get the formatted address:

$("#geocomplete").geocomplete().bind("geocode:result", function(event,result) {
    alert(result.formatted_address);
});

I just would like to do the same with the street_number.

John Slegers
  • 45,213
  • 22
  • 199
  • 169
Baylock
  • 1,246
  • 4
  • 25
  • 49
  • 1
    can you log/dump the whole result object ? – Eric Feb 21 '14 at 20:00
  • I'm sorry Eric but I don't get your question. If I log the formatted_address, I get the address alright but it's not what I need. As I don't know what is the variable to call in order to get the street_number (that is my real target), I, just don't know what to log. Can you tell me what do you have in mind? Thank you for your help. – Baylock Feb 21 '14 at 20:11
  • 1
    console.log(result); or even for(var a in result){console.log(a+'='+result[a]);} – Eric Feb 21 '14 at 20:12
  • Yes, it shows different objects and amongst them is "address_components:Array[6]". the Array[0] of this object has "long_name" and "short_name" in it which are both the street_number I would like to get. So this is the path: result => address_components => array[0] => long_name => '666'. Now how can I retrieve this in my result? Thank you very much! – Baylock Feb 21 '14 at 20:26
  • 1
    result.address_components[0].long_name – Eric Feb 21 '14 at 20:28
  • We are half way there, thank you, but this seems to be contextual: If the address doesn't have a street number , the same script will then log the street name instead, not an empty street number. So this will never guarantee me that it will bring me any information about the street_number. It will bring me the information about the first element it finds in the array, whatever it is. Am I right? My point is precisely to detect if a street number has been entered and this will always bring me a positive result even if there is no street number entered... – Baylock Feb 21 '14 at 20:34
  • check that your long_name is a numeric value then – Eric Feb 21 '14 at 20:35
  • It will not help because even my own street number is "104B" and there are countries where this "104b" could be a street name as well.. Is there no way to get directly the street_number, whatever it is? after a submit I can get the exact street number via a post variable, I just try to get the same directly with jquery before submitting. – Baylock Feb 21 '14 at 20:39
  • then check if the first piece of string before the first space (like 104B street of doom) contains numeric values and grab the whole thing. So it could be 104 or 104B. result.address_components[0].long_name.split(' ')[0]; – Eric Feb 21 '14 at 20:43
  • Sorry but these are dangerous workarounds. Th same use case could involve a district number, a zip code and so on (they all are numbers as well). What I need is to get what is really the street number and detected as such by the system. An educated guess could work 90% of the time but I need it to be 100% accurate. I'm pretty sure there is a way to get the street number value and not the "first-array-value-whatever-it-is". I value your help a lot but this solution doesn't fit my need. – Baylock Feb 21 '14 at 21:04
  • You have data inconsistencies issue. Fix that 1st :) – Eric Feb 21 '14 at 21:11
  • That's the problem. the inconsistency is not from my side. I get the result given by the Google API which brings a success with no consideration regarding the fact that the user entered a street_number or not. So I have to figure out a way to check afterwards if the street_number is there or not in order to fix this inconsistency. Easy enough after a submit because the API gives me a specific output for the street_number but I just can't get that output before submitting (even though I can get the formatted address, weird). My point is precisely to fix the problem you are referring to. – Baylock Feb 21 '14 at 21:21
  • then it's a "workaround" :) – Eric Feb 21 '14 at 21:25
  • Don't mind a workaround, just not a dangerous one. If it's accurate 100% of the time it's fine. Otherwise, not. It's a shipping system, it's too sensitive. I'm pretty sure there is a way to retrieve the proper value as the API allows it. Just don't know the proper syntax to use for geocomplete. – Baylock Feb 21 '14 at 21:31
  • Have you found a solution? I am having the same problem. – Irina Rapoport Jun 28 '15 at 16:10
  • No, sorry, i haven't. – Baylock Jun 28 '15 at 20:14

0 Answers0