Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6964715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:57:34+00:00 2026-05-27T15:57:34+00:00

Hi I would like to have an explanation regarding the following code. Here Sometimes

  • 0

Hi I would like to have an explanation regarding the following code. Here Sometimes my javascript functtion is working and sometime it is not. As a result, I don’t really know where is the problem. Here my index.html file automatically loads a map position. Then I call the javascript function with current lat,lng as argument. SO, initially it loads the by default map. Then the map should be overridden by the javascript function. The problem is sometimes it happens and sometimes it doesn’t. So, I would like to have an answer regarding this.

public class MapOptionsDemoModified extends Activity{
    //Geocoder geocoder;
    WebView mWebView;
    LocationManager mlocManager=null;
    LocationListener mlocListener;
    private MyLocationOverlay myLocationOverlay;
    protected MapView map; 
    private RadioButton mapButton;
    private RadioButton satelliteButton;
    private ToggleButton trafficToggle;
    private ToggleButton labelsToggle;
    private Configuration config;
    EditText LOC;
    Button routesbtn,settingsbtn;
    public String location="State Street"
    double lati,longi;
    GeoPoint currentLocation;
    double curlat,curlong;
    InputMethodManager imm;
    //String adrs;
    double latitude=40.07546;
    double longitude=-76.329999;


    String adrs="";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_options_modified);
        lati=34.1161;
        longi=-118.149399;
        adrs="";
        routesbtn=(Button)findViewById(R.id.mom_bt2);

        mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        mlocListener = new MyLocationListener();
        mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
        mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER);


        mWebView = (WebView) findViewById(R.id.webview);
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mWebView.loadUrl("file:///android_asset/index.html");
        //mWebView.loadUrl("http://www.google.com");
        webSettings.setBuiltInZoomControls(true);
        webSettings.setSupportZoom(true);
        imm=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);




        /* taking data from caller activity page */  
        // ###################Receiving data starts
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
         return;
        }
        lati=extras.getDouble("latitude");
        longi = extras.getDouble("longitude");
        adrs=extras.getString("adrs");

        // ##### Receiving data ends


        AlertDialog.Builder pdb=new AlertDialog.Builder(MapOptionsDemoModified.this);          
        pdb.setTitle("GPS");
        pdb.setMessage(adrs+" "+Double.toString(lati)+" "+Double.toString(longi));
        pdb.setPositiveButton("Ok", null);
        pdb.show();


        mWebView.loadUrl("javascript:getCurrentLocation("+lati+","+longi+")");


        routesbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                if(mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
                    //while(j<cnt)
                    //{

                        mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
                        if(MyLocationListener.latitude>0)
                        {
                            latitude=MyLocationListener.latitude;
                            longitude=MyLocationListener.longitude;
                            //flag=1;

                            Geocoder gcd = new Geocoder(MapOptionsDemoModified.this, Locale.getDefault());
                            List<Address> addresses;
                            try {
                                addresses = gcd.getFromLocation(latitude,longitude, 5);
                                if (addresses.size() > 0)
                                {
                                    adrs=addresses.get(0).getAddressLine(0)+" "+addresses.get(0).getAddressLine(1)+" "+addresses.get(0).getAddressLine(2);
                                }
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                            //break;

                            finish();
                            Intent i = new Intent(MapOptionsDemoModified.this,RoutesPageOne.class);
                            i.putExtra("adrs", adrs);
                            i.putExtra("latitude", latitude);
                            i.putExtra("longitude", longitude);
                            startActivity(i);




                        }
                        else
                        {

                            AlertDialog.Builder pdb=new AlertDialog.Builder(MapOptionsDemoModified.this);          
                            pdb.setTitle("GPS");
                            pdb.setMessage("GPS activation in progress");
                            pdb.setPositiveButton("Ok", null);
                            pdb.show();

                        }

                    //}

                }   
                else {

                    AlertDialog.Builder pdb=new AlertDialog.Builder(MapOptionsDemoModified.this);          
                    pdb.setTitle("GPS");
                    pdb.setMessage("GPS is not turned on..., please start gps");
                    pdb.setPositiveButton("Ok", null);
                    pdb.show();
                }

            }
        });




        LOC=(EditText)findViewById(R.id.mom_editText1);     
        LOC.setOnKeyListener(new OnKeyListener() {

            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // TODO Auto-generated method stub
               location = LOC.getText().toString();

                if (keyCode == KeyEvent.KEYCODE_ENTER && location.length() > 0) {

                    LOC.setText("");

                    imm.hideSoftInputFromWindow(LOC.getWindowToken(), 0);

                    mWebView.loadUrl("javascript:getLocation('" + location + "')");


                    /*AlertDialog.Builder edb=new AlertDialog.Builder(MapOptionsDemoModified.this);          
                    edb.setTitle("gps");
                    edb.setMessage(location+" lat= "+lati+" long="+longi);
                    edb.setPositiveButton("Ok", null);
                    edb.show();*/



                    //searchBarcode(barcode);
                    return true;
                }

                return false;
            }

            });



        //imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        mWebView.setWebViewClient(new HelloWebViewClient());






    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
            mWebView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:57:35+00:00Added an answer on May 27, 2026 at 3:57 pm

    The problem was in timing. Sometimes, the first url took more time to be loaded, as a result the 2nd url wasn’t invoked. So I have included SystemClock.sleep(1000) in between loadUrl calls and it has worked like a charm.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a detailed explanation. How would I use the Lua
I would like to have a negative inner padding / margin (not to affect
Here is yet another problem which I would like some explanation on. On line
I have a problem that I would like have solved via a SQL query.
I would like to have a reference for the pros and cons of using
I would like to have an iframe take as much vertical space as it
I would like to have a VM to look at how applications appear and
We would like to have user defined formulas in our c++ program. e.g. The
I would like to have a nice template for doing this in development. How
I would like to have all developers on my team to use the same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.