Rest API не вызывает от JavaScript до android, но работает в браузере - PullRequest
0 голосов
/ 10 февраля 2020
        <?php 




    $conn = mysqli_connect('localhost','eyukti_home_roc','4nYntQuCjPYR','eyukti_home_roc');

    $user_id = $_GET['user_id'];


    $sql = mysqli_query($conn,"SELECT * FROM `vehicle_type` WHERE status = '1' AND is_delete !='1'"); 


    include("../firebase.php");       
    ?>

    <script>
    (function() {
      // Initialize the Firebase SDK
    firebase.initializeApp({
     databaseURL: "https://xxx-xxxx.firebaseio.com"
    });

    var  user_new_lat = null;
    var  user_new_lng = null;

    var ref_driver_location = firebase.database().ref('Driver/DriverLocation');

    var  ref_user = firebase.database().ref('User').child('<?php echo $user_id; ?>');
    var ref_nearest_driver = ref_user.child('NearestDriver');
    var ref_availableDriver = ref_user.child('availableDriver');
    var ref_driver = firebase.database().ref('Driver');
    var geoFire = new geofire.GeoFire(ref_driver_location);


    var user_new_location = ref_user.child('UserLocation/UserLocationNew');
    var user_old_location = ref_user.child('UserLocation/UserLocationOld');


    var user_location = ref_user.child('UserLocation');

         var user_new = ref_user.child('UserLocation/GeoLocation');

    var geoQuery = null;


    user_old_location.on("value", function(newuser_snapshot) {


    user_location.once("value", function(nearest_driver_snapshot) {

           user_new_lat = nearest_driver_snapshot.child("GeoLocation/location/l/0").val();
           user_new_lng = nearest_driver_snapshot.child("GeoLocation/location/l/1").val();  
         var user_old_lat = nearest_driver_snapshot.child("UserLocationOld/lat").val();
         var user_old_lng = nearest_driver_snapshot.child("UserLocationOld/lng").val();



                var geoFireUserLocation = new geofire.GeoFire(user_new);     
                var geoQueryUserLocation = geoFireUserLocation.query({
                    //alert('yes');
                  center: [parseFloat(user_old_lat),parseFloat(user_old_lng)],
                  radius: 0.6
                });


                     var onReadyRegistration = geoQueryUserLocation.on("ready", function() {
                  console.log("GeoQuery has loaded and fired all other events for initial data");
                });


                var onKeyEnteredRegistration = geoQueryUserLocation.on("key_entered", function(key, location, distance) {


                                 geoQuery = geoFire.query({
                                  center: [parseFloat(user_old_lat),parseFloat(user_old_lng)],
                                  radius: 3.0
                                });










    }, function (error) {
       console.log("Error: " + error.code);
    });



    }, function (error) {
       console.log("Error: " + error.code);
    });


    })();


    </script>

    <!--<script src="../firebase_js/insertuser.js" defer></script>-->

Проблема в том, что Geofire работает, когда я запускаю этот API из браузера, но не нажимаю, когда я вызываю этот API в android Я пытался вызвать API в почтальоне, но он дает ответ от php, но не запуск функции geofire, а также выдача javascript кода в ответ. Я не могу найти решение, потому что я не могу найти проблему

1 Ответ

0 голосов
/ 10 февраля 2020

Если вы используете веб-просмотр в android, вам нужно включить javascript для веб-просмотра следующим образом

WebView mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
mWebView.loadUrl("htpps://yoururl");
...