Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function codeAddress(address) {
  2.     const fetchAddress = (resolve) => {
  3.         const geocoder = new google.maps.Geocoder();
  4.         const parseResult = (results, status) => {
  5.             if (status !== google.maps.GeocoderStatus.OK) {
  6.                 resolve([])
  7.                 return;
  8.             }
  9.             resolve([
  10.                 results[0].geometry.location.lat(),
  11.                 results[0].geometry.location.lng()
  12.             ]);
  13.         };
  14.         geocoder.geocode({ address: address, language: 'english' }, parseResult);
  15.     }
  16.     return new Promise(fetchAddress);
  17. }
  18.  
  19. // uzycie
  20.  
  21. codeAddress('address').then(result => {
  22.     console.log(result)
  23. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement