2016-04-12 11 views
2

Dies ist mein erstes Google Map API-Projekt, und ich erstelle eine Transport-App, aber leider funktioniert es nicht, früher funktionierte es, aber jetzt funktioniert es nur im Browser nicht auf Handy und Emulator.Nicht in der Lage, Google Map in Intel XDK mit Google Map API zu sehen JS

Im Emulator zeigt es nur Google Logo und Terms Link.

Ich bin mit dieser Referenz Google-Verbindung

<script type="text/javascript" src="http://maps.google.com/maps/api/js?key=MYKEY&libraries=places"></script> 

meine JS-CODE: (mapwork.js)

function currentpostionmap() 
{ 
     if (navigator.geolocation) { 


        function success(pos) 
     { 
             var latlng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude); 
       var myOptions = { 
            zoom: 15, 
            center: latlng, 
            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 
         
        }); 
       bounds.extend(latlng); 
        map.fitBounds(bounds); 
//    
        multimarker(map); 
//    

        } 
        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 
            
         }); 


        } 
        // Find the users current position.  Cache the location for 5 minutes, timeout after 6 seconds 
      navigator.geolocation.getCurrentPosition(success, fail, {maximumAge: 500000, enableHighAccuracy:true, timeout: 6000}); 
    } 
} 
function multimarker(map) 
{ 
      jQuery.ajax({        
    url: baseurl + "getdriverlocation.php", 

    async: true, 
    success: function(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; 
     locations.push([driverlat , driverlng]) 
}); 



for (i = 0; i < locations.length; i++) 
       { 
       var latlng1 = new google.maps.LatLng(locations[i][0], locations[i][1]); 

      drivermarker=new google.maps.Marker({position:latlng1}); 
      drivermarker.setMap(map); 

      google.maps.event.addListener(drivermarker, 'click', (function(marker, i) { 
      return function() { 

      //DRIVER CLICK EVENT 
     } 
     })(drivermarker, i)); 



       } 


} 

}); 

} 
function watchDriverPosition(userid) 
{ 
    function success(pos) 
    { 
     window.setInterval(function(){ 
      saveDriverLocation(pos.coords.latitude, pos.coords.longitude,userid); 
     }, 50000); 
    } 
    function fail() 
    { 
     alert ('Fail to watch drivers Position'); 
    } 
    watchId = navigator.geolocation.watchPosition(success, fail, {maximumAge: 500000, enableHighAccuracy:true, timeout: 6000}); 

} 
function saveDriverLocation(latc,lngc,userid) 
{ 

    jQuery.ajax({ 
url: baseurl + "postdriverlocation.php", 
data:'latitude='+latc +'&longitude='+lngc+'&login_id='+userid, 
type: "POST", 
success:function(response){ 
    response = $.trim(response); 
    if (response == "false"){ 
     console.log(response); 


    }else{ 
     console.log(response); 
    } 


}, 
error:function(){} 
}); 
} 

CALLING MAP-Funktion HIER (main.js)

function showmap(usertype,userid) 
    { 
     if (usertype==1) 
      { 
          changepage('#main'); 
       currentpostionmap(); 

      } 
     else if (usertype==0) 
      { 

       watchDriverPosition(userid); 

      } 
     else{ 
      alert('You are not logged in.'); 
      changepage('#login'); 
     } 
    } 

Es funktioniert bei jedem Browser aber nicht bei EMULATOR oder MOBILTELEFON.

Bitte lassen Sie mich wissen, warum es passiert ist und eine bessere Lösung

Dank

Antwort

2

Wickeln Sie Ihre Karte Code

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

//your map code... 

}); 
+0

Danke, es funktioniert für mich –