2016-05-21 8 views
0

Ich erstelle eine App, die Benutzer Ort verfolgt und markieren Sie mehrere Markierungen auf der Karte.Google Map funktioniert nicht in Intel xdk Emulator funktioniert aber gut in jedem Browser mit jquery mobile

Obwohl meine App funktioniert gut in Browsern, aber nicht in Intel XDK Emulator und Handys.

Cordova CLI Version: 5.4.1 Intel XDK Version: 3240

unten ist mein Code:

function currentpostionmap() { 
    $(document).on("pageshow", "#inside123", function() { 

       
     if (navigator.geolocation) { 
               
      function success(pos) {             
       userClat = pos.coords.latitude; 
       userClng = pos.coords.longitude; 
       var latlng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);  
       var myOptions = {             
        zoom: 15, 
        center: latlng, 
        disableDefaultUI: true, 
        zoomControl:true, 
        mapTypeId: google.maps.MapTypeId.ROADMAP,         
       };         
       map = new google.maps.Map(document.getElementById("map"), myOptions);       
       var image123 = 'https:///developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'; 
       //    var bounds = new google.maps.LatLngBounds();         
       marker = new google.maps.Marker({             
        position: latlng, 
        map: map, 
        icon: image123                 
       }); 

       var infowindow1 = new google.maps.InfoWindow(); 

       google.maps.event.addListener(marker, 'click', (function (marker, i) { 
        return function() { 
         infowindow1.setContent('YOU'); 
         infowindow1.open(map, marker); 
         map.setZoom(20); 
         map.setCenter(marker.getPosition()); 

        } 
       })(marker)); 

       multimarker(map, latlng, infowindow1);         
      }         
      function fail(error) {           
       var latlng = new google.maps.LatLng(18.5204, 73.8567);  
       var myOptions = {             
        zoom: 10, 
                    center: latlng, 
                    mapTypeId: google.maps.MapTypeId.ROADMAP         
       };         
       map = new google.maps.Map(document.getElementById("map"), myOptions);              
       marker = new google.maps.Marker({             
        position: latlng, 
                    map: map                    
       }); 


                
      }        
      navigator.geolocation.getCurrentPosition(success, fail, { 
       maximumAge: 500000, 
       enableHighAccuracy: true, 
       timeout: 6000 
      });     
     } 
    }); 

} 
function getlocation() 
{ 
     if (navigator != null) { 
     if (navigator.geolocation) { 

     function success(position) { 

      userClat = position.coords.latitude; 
      userClng = position.coords.longitude;    
      goToLogin();  

     } 

     function fail(error) { 
      if (error.code == PositionError.PERMISSION_DENIED) { 
       alert("App doesn't have permission to use GPS"); 
      } else if (error.code == PositionError.POSITION_UNAVAILABLE) { 
       alert("No GPS device found"); 
      } else if (error.code == PositionError.TIMEOUT) { 
       alert("Its taking too much time to find user location"); 
      } else { 
       alert("An unknown error occured"); 
      } 
     } 

     navigator.geolocation.getCurrentPosition(success, fail, { 
      maximumAge: 500, 
      enableHighAccuracy: true, 
      timeout: 600 
     }); 


    } 
     } 
    else 
     { 
      console.log ('NAVIGATOR ERROR'); 
     } 
} 


function multimarker(map, userloc, infowindow) { 

    jQuery.ajax({ 
     url: baseurl + "getdriverlocation.php", 

     async: true, 
     success: function (data) { 
      data = $.trim(data); 
      if (data == "false") { 
       $('#footInfo').html('<p>No Driver Registered</p>'); 


      } else { 
       //  console.log(data) 
       var myArray = jQuery.parseJSON(data); // instead of JSON.parse(data) 

       jQuery(myArray).each(function (index, element) { 
        driverlat = element.driver_lat; 
        driverlng = element.driver_lng; 
        loginid = element.loginid; 
        locations.push([driverlat, driverlng, loginid]) 
       }); 
       var bounds1 = new google.maps.LatLngBounds(); 

       for (i = 0; i < locations.length; i++) { 

        var latlng1 = new google.maps.LatLng(locations[i][0], locations[i][1]); 
        if (google.maps.geometry.spherical.computeDistanceBetween(latlng1, map.getCenter()) < 30000) { 
         drivermarker = new google.maps.Marker({ 
          position: latlng1, 
          icon: "img/car.png", 
          map: map 
         }); 
         drivermarker.setMap(map); 

         google.maps.event.addListener(drivermarker, 'click', (function (marker, i) { 
          return function (evt) { 
           //  infowindow.setContent(locations[i][2]); 
           //  infowindow.open(map, marker); 
           driverdetail(locations[i][2]); 
          } 
         })(drivermarker, i)); 
         bounds1.extend(latlng1); 
         map.fitBounds(bounds1); 
        } 
       } 
       bounds1.extend(userloc); 
       map.fitBounds(bounds1); 
       // wait for the bounds change to happen 
       google.maps.event.addListenerOnce(map, 'bounds_changed', function() { 
        // set the center on the user 
        map.setCenter(userloc); 
        // wait for the center to change 
        google.maps.event.addListenerOnce(map, 'bounds_changed', function() { 
         // check to see if all the markers are still in bounds 
         if ((!map.getBounds().contains(bounds1.getNorthEast())) || 
          (!map.getBounds().contains(bounds1.getSouthWest()))) { 
          // if not zoom out one level 
          //      console.log(map.getZoom() + " zoom-1 will be " + (map.getZoom() - 1)); 
          map.setZoom(map.getZoom() - 1); 
         } 
        }); 
       }); 
      } 
     } 
    }); 
} 
google.maps.event.addDomListener(window, "load", currentpostionmap); 

function watchDriverPosition(userid) { 

    $(document).on("pageshow", "#drivermain", function() {  
     if (navigator.geolocation) { 
      function success(position) { 

       window.setInterval(function() { 
        updateDriverLocation(position.coords.latitude, position.coords.longitude, userid); 
       }, 50000); 
      } 

      function fail(error) { 
       if (error.code == PositionError.PERMISSION_DENIED) { 
        alert("App doesn't have permission to use GPS"); 
       } else if (error.code == PositionError.POSITION_UNAVAILABLE) { 
        alert("No GPS device found"); 
       } else if (error.code == PositionError.TIMEOUT) { 
        alert("Its taking to find user location"); 
       } else { 
        alert("An unknown error occured"); 
       } 
      } 
      watchId = navigator.geolocation.watchPosition(success, fail, { 
       maximumAge: 500000, 
       enableHighAccuracy: true, 
       timeout: 6000 
      }); 
     } 
    }); 
} 



$(document).ready(function() { 
     console.log("ready!"); 

     getlocation(); 

    }); 

Jedes Mal, wenn der App auf Emulator startet, es gibt mir zwei Warnungen erstes ist

Die Einnahme Benutzerstandort

zu finden 210

Zweitens ist

ist ein unbekannter Fehler aufgetreten

Dies ist meine erste mobile app ich schwer zu erreichen, so viel hat wirklich funktioniert, bitte mir in dieser Hinsicht helfen.

Antwort

0

mit Intel XDK und Cordova einige Funktionen müssen mit einigen Skripten von der richtigen Intel XDK-Bibliothek zur Verfügung gestellt werden.

Im Fall von Geolocation Sie es mit diesem Aufruf aufrufen muss

intel.xdk.geolocation.watchPosition (suc, ausfallen, Optionen);

und hier ist ein Beispielcode

https://software.intel.com/en-us/xdk/article/intel-xdk-geolocation-sample

Beachten Sie, dass Bilder zum Beispiel das Hochladen von direkt auf Browser ausgeführt wird, etwas zu Handy oder Kamera zugreifen ähnlich, so in HTML muss man die Kamera oder Datei-Browser zugreifen können aber nicht in cordova und xdk gepackte app, die auf die hardware zugreifen muss.

Hoffnung, dies hilft Ihnen

+0

Es funktioniert nicht ich die 'navigator.geolocation' zu' intel.xdk.geolocation' geändert haben dann auch ist es nicht wrking –

+0

und diesen Fehler 'kippe Eigenschaft‚watchPosition‘lesen ' –

+0

Weil es nicht nur notwendig ist, die Funktion aufzurufen. Muss die gesamte Dokumentation lesen. –