Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Google Geocoder cant find latitude and longitude of array of addresses.

$
0
0

Hello Guys, I am using 3.2.0 SDK. I m trying to find latitude and longitude from html file and trying to get that lat long array on JS file.

here is my code, plz give me solution asap.

app.js

var webView = Ti.UI.createWebView({
        url : 'test.html'
});
 
function loadFromHtmlFile() {
        webView.reload();
 
        webView.addEventListener('load', function(e) {
            Ti.App.fireEvent('app:fromTitanium', {
                data : dicCollect//Array of dictionary
            });
        });
    }
 
 
 
Ti.App.addEventListener('app:fromHtml', function(e) {
            var tempColl = e.data;
 
            for ( i = 0; i < tempColl.length; i++) {
                var temp = tempColl[i];
                Ti.App.newLats = temp.lat;
                Ti.App.newLongs = temp.lng;
            }
    });

test.html

<!DOCTYPE html>
<html>
 
    <head>
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
        <title>Google Maps JavaScript API v3 Example: Directions Waypoints</title>
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
        <script type="text/javascript">
            var latLongColl = [];
            var tempColl = [];
            var index = 0;
            var geocoder;
            var map = '';
 
            function getLatLong(address) {
                // var geocoder = new google.maps.Geocoder();
                var result = "";
                geocoder.geocode({
                    'address' : address,
                }, function(results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
 
                        var latLong = {
                            lat : results[0].geometry.location.lat(),
                            lng : results[0].geometry.location.lng(),
                            sts : status,
 
                        };
                        latLongColl.push(latLong);
 
                    } else {
                        result = "Unable to find address: " + status;
                    }
                });
            }
 
            var loadDataFunc = function(et) {
                Ti.API.info('Entered in app:fromTitanium');
                Ti.API.info('load data function Called' + JSON.stringify(et.data));
                // var tadd = et.data[i].address + ',' + et.data[i].city + ',' + et.data[i].state + ',' + et.data[i].zip;
                for (var i = 0; i < et.data.length; i++) {
                    var add = et.data[i].address + ',' + et.data[i].city + ',' + et.data[i].state + ',' + et.data[i].zip;
                    tempColl.push({
                        address : add
                    });
                    getLatLong(add);
                }
 
            };
 
            Ti.App.addEventListener('app:fromTitanium', loadDataFunc);
 
            function removeFireEvent() {
                Ti.App.removeEventListener('app:fromTitanium', loadDataFunc);
            }
 
            function fireGeoLatLong() {
                Ti.App.fireEvent('app:fromHtml', {
                    data : latLongColl,
                });
 
                // google.maps.event.addDomListener(window, 'unload', fireGeoLatLong);
 
            }
        </script>
    </head>
    <body  onunload="removeFireEvent()">
        <div id="map_canvas" style="float:center;width:758px;height:350px;"></div>
    </body>
</html>

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>