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

后端 未结 5 1203
死守一世寂寞
死守一世寂寞 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:01

    Have you tried this?

    $(".geocodethis").click(function () {
        var geocoder = new GClientGeocoder();
        var postalCode = $(this).siblings(".postal").val();
        var id = $(this).siblings(".id").val();
    
        geocoder.getLatLng(postalCode, function (point) {
            if (!point) {
                alert(postalCode + " not found");
            } else {
                alert(point);
                var marker = new GMarker(point);
                map.addOverlay(marker);
                obj = {lat: marker.position.lat(),
                       lng: marker.position.lng()};
                $.post("/Demographic/Geocode/" + id, obj, function () {
                    alert("success?");
                });
            }
        });
    
    });
    

    I haven't used V2 in a long time, so I'm not sure about the exact syntax, but the point is to create an object from the information you need (lat/lng) and serialize that.

    Also, an upgrade to V3 is much recommended, if plausible.

提交回复
热议问题