How do I use Google Maps geocoder.getLatLng() and store its result in a database?

后端 未结 5 1209
死守一世寂寞
死守一世寂寞 2021-01-04 10:10

Hey everybody! Im trying to use getLatLng() to geocode a list of postal/zip codes and store the generated point in the database to be placed on a map later. This is what I\'

5条回答
  •  遥遥无期
    2021-01-04 11:02

    If your stuck for 2 days maybe a fresh v3 start would be a good thing, this snipped does a similair job for me...

              function GetLocation(address) {
              var geocoder = new google.maps.Geocoder();
              geocoder.geocode({ 'address': address }, function (results, status) {
                  if (status == google.maps.GeocoderStatus.OK) {
                      ParseLocation(results[0].geometry.location);
    
                  }
                  else
                    alert('error: ' + status);
    
              });
          }
    
      }
    
      function ParseLocation(location) {
    
          var lat = location.lat().toString().substr(0, 12);
          var lng = location.lng().toString().substr(0, 12);
    
          //use $.get to save the lat lng in the database
          $.get('MatchLatLang.ashx?action=setlatlong&lat=' + lat + '&lng=' + lng,
                function (data) {
                    // fill textboss (feedback purposes only) 
                    //with the found and saved lat lng values
                    $('#tbxlat').val(lat);
                    $('#tbxlng').val(lng);
                    $('#spnstatus').text(data);
    
    
                });
        }
    

提交回复
热议问题