0

I'm trying to making a form that can retrieve address, longitude, latitude and the city name..

I have try address, longitude and latitude but stuck in the city name

Here's the code

<script type="text/javascript">
    $(document).ready(function() {
        $("#searchBox").autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: "http://dev.virtualearth.net/REST/v1/Locations",
                    dataType: "jsonp",
                    data: {
                        key: "----",
                        q: request.term
                    },
                    jsonp: "jsonp",
                    success: function(data) {
                        var result = data.resourceSets[0];
                        if (result) {
                            if (result.estimatedTotal > 0) {
                                response($.map(result.resources, function(item) {
                                    return {
                                        data: item,
                                        label: item.name + ' (' + item.address.countryRegion + ')',
                                        value: item.name
                                    }
                                }));
                            }
                        }
                    }
                });
            },
            minLength: 1,
            change: function(event, ui) {
                if (!ui.item)
                    $("#searchBox").val('');
            },
            select: function(event, ui) {
                displaySelectedItem(ui.item.data);
            }
        });
    });

    function displaySelectedItem(item) {
        $("#searchResult").empty().append('Data Result: ' + item.name).append(' (Latitude: ' + item.point.coordinates[0] + ' Longitude: ' + item.point.coordinates[1] + ' City Name: ' + item.cityname + ')');
    }
</script>

For the code, I have try to use ' City Name: ' + item.cityname but it seems it can't print the city name which right now, the output is undefined.

Any help is appreciated for me to accomplish my job. thanks :)

Narendra Jadhav
  • 10,052
  • 15
  • 33
  • 44
YCRZ
  • 1
  • 2

0 Answers0