Quantcast
Channel: SCN : Discussion List - SAP for Mobile
Viewing all articles
Browse latest Browse all 5806

How to get current location?

$
0
0

http://scn.sap.com/message/14315884#14315884

 

I'm following above to make Geo location work.I do not have idea what "hwc" object it and how can i declare this...So I commented that part and hard coded my latitude and longitude; Just called "run" method from "function customBeforeNavigateForward(screenKey, destScreenKey)".

 

When I start my application from the container, it showed me the start screen. Then I click on get location, it showed me following message.Location.jpgOn click "OK" its navigating to location screen but not shoing me map/location.What could be the problem?

Following is my code in custom.js:

 

function customBeforeNavigateForward(screenKey, destScreenKey) {

/*

    if (screenKey == "Desc" && (destScreenKey === "Create"))

    {

        var form = document.forms[screenKey + "Form"];

        if (form)

        {

            var desc = form.ExpenseTracking_create_itemDesc_paramKey.value;

            var reason = form.ExpenseTracking_create_reason_paramKey.value;

            if (desc.length == 0 && (reason.length == 0 )) {

                var helpElem = document.getElementById(screenKey + "Form_help");

                setValidationText(helpElem, "Desc or reason must be provided.  Preferably both.");

                return false;

            }

        }

    }

*/

    //var hwc = new Custom();

    //hwc.customBeforeNavigateForward = function(screenKey, destScreenKey)

    //{

        //for Geo Location getting Lat and Long values:

 

       // if(destScreenKey === "Geo_Location")

        //{

          //  var state = document.readyState;

            //if (state == 'loaded' || state == 'complete')

            //{

                run();

            //}

           // else

            //{

              //  if (navigator.userAgent.indexOf('Browzr') > -1)

                //{

                  //  setTimeout(run, 250);

                //}

               // else

                //{

                  //  document.addEventListener('deviceready',run,false);

                //}

            //}

 

        //}//geo location

    //}

   

    return true;

}

//geo location run method called from customBeforeNavigateForward

 

//"http://maps.google.com/maps/api/staticmap?center=" + 50.448574 + "," + 104.608917 + "&zoom=13&size=320x480&maptype=roadmap&key=<enter your google developer id key>&sensor=true"

function run() {

 

      var win = function(position) {                          // Grab coordinates object from the Position object passed into success callback.

 

           var coords = position.coords;

 

           // Call for static google maps data - make sure you use your own Google Maps API key!

 

           var url = "http://maps.google.com/maps/api/staticmap?center=" + 50.448574 + "," + 104.608917 + "&zoom=13&size=320x480&maptype=roadmap&key=MY GOOGLE API KEY&sensor=true";

 

          // document.getElementById('map').setAttribute('src',url);

 

          hwc.showAlertDialog(coords.latitude + ":" + coords.longitude);

 

      };

 

      var fail = function(e) {

 

           hwc.showAlertDialog('Can\'t retrieve position.\nError: ' + e);

 

      };

 

      navigator.geolocation.getCurrentPosition(win, fail);

 

    }


Viewing all articles
Browse latest Browse all 5806

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>