Software Archive
Read-only legacy content
17061 Discussions

ANY HINT why the code (also posted below) fails in Device although work in browser or ripple?

Leonidas_S_
New Contributor I
511 Views

https://forums.html5dev-software.intel.com/viewtopic.php?f=34&t=11033&p=36038#p36038

BASED ON THIS^

ANY HINT why the code (also posted below) fails in Device although work in browser or ripple?

with XDK INTEL can use any editor? eg can edit in NetBeans run Cordova: android emulator in Netbeans,.. and still have the project in XDK IDE...Is this OK?

        function onDeviceReady() {
            checkConnection();
        }

        function checkConnection() {
            var networkState = navigator.connection.type;

            if (networkState == Connection.NONE  || networkState == Connection.CELL_2G)
            alert("This App requires Internet Connection!\nPlease shut down App, connect and reopen App!");
            
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
            }            
            
        }

function successFunction(position) {
    var lat = position.coords.latitude;
    var lng = position.coords.longitude;
    //alert(lat +" , "+lng);
   localStorage.setItem("lat", lat);
   localStorage.setItem("lng", lng);
    codeLatLng(lat, lng)
}
function errorFunction(){
    alert("Geocoder failed");
}


function codeLatLng(lat, lng) {
    
    var geocoder;
    geocoder = new google.maps.Geocoder(); 
    var latlng = new google.maps.LatLng(lat, lng);
    geocoder.geocode({'latLng': latlng}, function(results, status) {
        var address_line;
        if (status == google.maps.GeocoderStatus.OK) {
            if (results[1]) {
                address_line = results[0].formatted_address;
                //console.log(address_line);
                $('#user-location').html(address_line);
                $('input[name="latlng"]').val(lat+','+lng);
            } else {
                $('#user-location').html("No results found - but you can search.");
            }
        } else {
            $('#user-location').html("Geocoder failed due to: " + status);
        }
    });
}

 

0 Kudos
5 Replies
Amrita_C_Intel
Employee
511 Views

Absolutely, just open your files and edit them in your favorite editor. However, note that you must use Brackets to use the "Live Layout Editing" feature. 

Some popular editors among our users include:

Notepadd++ for a lighweight editor

Jetbrains editors (Webstorm)

Vim the editor

CodeLobster

0 Kudos
Leonidas_S_
New Contributor I
511 Views

When in Netbeans run cordova (Android native emulator) I have to have a config.xml file other than XDK Config file?

0 Kudos
PaulF_IntelCorp
Employee
511 Views

Regarding your geo code, on a real device there is more complexity required of your code to insure you get a reading. See the file named cordova-geo.js in this sample app: https://github.com/xmnboy/hello-cordova. The app can be built and run on a real device, there are many comments and console.log messages to help you understand how it works. See this short tutorial for more help: https://github.com/xmnboy/hello-cordova/blob/master/docs/an-intel-xdk-debugging-tutorial.md

0 Kudos
Leonidas_S_
New Contributor I
511 Views
    geocoder = new google.maps.Geocoder();
    navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
 

 

//  Basically my code runs when i implement code with using one of these lines... If use both code not work.

//   you know how and in what order combine these two reverse geocode and detect current possition???

 

0 Kudos
PaulF_IntelCorp
Employee
511 Views

I'm not familiar with the internal workings of the Google Maps library. It sounds like they are using the geolocation functions, which makes sense, so you're going to have to peer into their library to see how it uses that feature and if it's possible for you to work with the geo subsystem in a way that is compatible with their library. I'm guessing that one of you is overwriting the others success fail event handlers.

Sorry, this is not an XDK issue but a library conflict issue. Might be best to post on Stack Overflow and be sure to mention that you are trying to use Google Maps in a Cordova application.

0 Kudos
Reply