GetDistance Javascript没有返回任何内容,同时具有一些参数值

时间:2016-03-26 10:30:24

标签: javascript latitude-longitude

我想从这个函数中得到一个结果。但是,没有任何内容返回到我的页面,只是“此示例调用执行计算的函数,并返回结果:”。我需要这个函数从属性表中获取数据库中的每个邮政编码并找到距离。此外,一个邮政编码总是设置相同所以我需要设置它,而另一个邮政编码将是属性表中的邮政编码。

<?php

    include ("../connect.php");

    ?>
    <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    </head>

    <body>
    <p>This example calls a function which performs a calculation, and returns the result:</p>

    <p id="demo"></p>

    <script type="text/javascript">
    var x = getDistance(52.482799000000000, -2.000643000000000, 52.48463500000000, -1.980759000000000);
    function getDistance($latitude1, $longitude1, $latitude2, $longitude2) {  
        $earth_radius = 6371;  

        $postLat = deg2rad($latitude2 - $latitude1);  
        $postLon = deg2rad($longitude2 - $longitude1);  

        $a = sin($postLat/2) * sin($postLat/2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($postLon/2) * sin($postLon/2);  
        $c = 2 * asin(sqrt($a));  
        $d = $earth_radius * $c;  
          //$distance_miles = $km * 0.621371; //distance in miles 
        return $d;
        document.getElementById("demo").innerHTML = x; 

    }
    </script>

    </body>
    </html>

1 个答案:

答案 0 :(得分:1)

你在哪里使用x变量?

我希望这样的事情:

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
    byte[] byteArray = stream.toByteArray();
image1 = new ParseFile("profilePhoto.png", byteArray);
image1.saveInBackground(new SaveCallback() {
        @Override
        public void done(ParseException e) {

            if (e == null) {
    upload();
            } else {

            }

        }
    });

    public void upload(){
JSONArray myFriendList = new JSONArray();
    myFriendList.put("xxxxxxxxxxxxxxx");
    myFriendList.put("yyyyyyyyyyyyyyy");

    ParseObject userSettingObj = new ParseObject("userSetting");
    userSettingObj.put("profileName",    profileNameField.getText().toString());
    userSettingObj.put("userid", ParseUser.getCurrentUser().getObjectId());
    userSettingObj.put("name", nameField.getText().toString());
    userSettingObj.put("surname", surnameField.getText().toString());
    userSettingObj.put("friendList", myFriendList);

    userSettingObj.put("photo", byteArray);

    userSettingObj.saveInBackground(new SaveCallback() {
        @Override
        public void done(ParseException e) {

            if (e == null) {

                System.out.println("saved successfully");

            } else {

                System.out.println("error while saving");

            }

        }
    });}