epos4u Posted May 28, 2016 Share Posted May 28, 2016 Hi, could someone please guide or help to assign a js script to update edit fields for address input Thank you js script ---------- function Read(postcode){ var country = 'GB' var urlfmt = 'https://maps.googleapis.com/maps/api/geocode/json?components=postal_code:'+postcode; if(country != undefined) urlfmt += '|country:'+country; var content = web.Download(urlfmt); var obj = JSON.parse(content); var lat = obj.results[0].geometry.location.lat; var lng = obj.results[0].geometry.location.lng; var addrurl = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='+ lat + ',' + lng + '&sensor=false' var addr = web.Download(addrurl); var addrObject = JSON.parse(addr); var data = GetAddressComponents(addrObject.results,postcode); if(data == null) return postcode; var street = ReadComponent('route',data); if(street == '-') street = ReadComponent('locality',data); if(street == '-') street = ReadComponent('administrative_area_level_4',data); var town = ReadComponent('postal_town',data); var county = ReadComponent('administrative_area_level_2',data); return postcode + ',' + street + ',' + town + ',' + county;}function GetAddressComponents(results,postcode){ for(i=0;i < results.length;i++) { for(j=0; j< results.address_components.length;j++) { var component = results.address_components[j]; if(component.long_name.replace(' ','') == postcode.replace(' ','')) return results.address_components; } } return null;}function ReadComponent(name,components){ for(i=0;i<components.length;i++) { var component = components; for(j=0;j<component.types.length;j++) { if(component.types[j] == name) return component.long_name; } } return '-';} Quote Link to comment Share on other sites More sharing options...
bugra Posted May 31, 2016 Share Posted May 31, 2016 I've wroted sample project. I hope it will help. Google Maps Geocoding.zip Quote Link to comment Share on other sites More sharing options...
epos4u Posted May 31, 2016 Author Share Posted May 31, 2016 Bugra Yener Sahinoglu, Thank you Quote Link to comment Share on other sites More sharing options...
epos4u Posted May 31, 2016 Author Share Posted May 31, 2016 I've wroted sample project. I hope it will help. Perfect, thank you so much Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.