PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label location. Show all posts
Showing posts with label location. Show all posts

Saturday, October 29, 2022

[FIXED] How can I reach End Of File?

 October 29, 2022     eof, indexing, java, location     No comments   

Issue

I am designing a program that saves the index location for specific characters from a message. Then, I need to retrieve these characters according to their index location. I kept the locations for these characters in a .txt file. I retrieved them, but at the end, I got this message "Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index 120 out of bounds for length 120". My codes:

int n;
String s; 
int lineNumCount = 0;
String coverText = stegoMsg.getText(); // get the stego text from the textfield
int k = coverText.length(); // get the length for the stego text
int lineNumb = 1;
Scanner myFile = null;
          try{
               Scanner file = new Scanner(new File("location.txt"));//location.txt is the file that has the locations for the characters
               myFile = file;
             }catch (FileNotFoundException e){
                 System.out.println("File does not found");
             }
        while (myFile.hasNextLine()){
            //Count the Number of the lines in location.txt
            //1. Read the File
            File fileLocation = new File("location.txt"); 
            if(fileLocation.exists()){
                try {
                    FileReader fr = new FileReader(fileLocation);
                    LineNumberReader lr = new LineNumberReader(fr); //2. Read the lines for location.txt
                    
                    while((lr.readLine()) !=null){
                    lineNumCount++;
                            }
                   // System.out.println("Total Number of the Lines " + lineNumCount);
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(ExtPage.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(ExtPage.class.getName()).log(Level.SEVERE, null, ex);
                }
            
           for(int x = 0; x<lineNumCount; ++x){
            try{
                String line = Files.readAllLines(Paths.get("location.txt")).get(lineNumb);
               // System.out.println("Line First " + line);
                BufferedReader bufrd = new BufferedReader(new FileReader("SFile.txt")); //SFile.txt is the file that has the messsage that I need to take the location for the specific characters
                int nn = Integer.parseInt(line);  
                s = bufrd.readLine();
                System.out.println("The Location " + nn  + " is : "+ s.charAt(nn)); // read the character that has this location
                lineNumb++;
                
                }catch(IOException e){
                    System.out.println("Line 334");
                }
           }
            }
        }
        myFile.close();
 }

Is it possible to guide me on how I can solve the exception? I appreciate any help you can provide.


Solution

Here is the solution ...

        int n;
        String s; 
        int lineNumCount = 0;
        String coverText = stegoMsg.getText(); // get the stego text from the textfield
        int k = coverText.length(); // get the length for the stego text
        int lineNumb = 1;
        Scanner myFile = null;
        try{
        Scanner file = new Scanner(new File("location.txt"));
        myFile = file;
        }catch (FileNotFoundException e){
            System.out.println("File does not found");
        }
       try{
        while (myFile.hasNext()){
            //Count the Number of the lines in location.txt
            //1. Read the File
            File fileLocation = new File("C:\\Users\\Farah\\Dropbox\\Steganography codes\\NewStegoTech\\location.txt");
            if(fileLocation.exists()){
                try {
                    FileReader fr = new FileReader(fileLocation);
                    LineNumberReader lr = new LineNumberReader(fr); //2. Read the lines for location.txt
                    
                    while((lr.readLine()) !=null){
                    lineNumCount++;
                            }
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(ExtPage.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(ExtPage.class.getName()).log(Level.SEVERE, null, ex);
                }
            
          try{
                String line = Files.readAllLines(Paths.get("location.txt")).get(lineNumb);
               // System.out.println("Line First " + line);
                BufferedReader bufrd = new BufferedReader(new FileReader("Stego File.txt"));
                int nn = Integer.parseInt(line);  
                s = bufrd.readLine();
                System.out.println("The Loocation " + nn  + " is : "+ s.charAt(nn)); // read the character that has this location
                lineNumb++;
                }catch(IOException e){
                    System.out.println(e);
                }
           
            }
        }
       }catch(IndexOutOfBoundsException e)
       {
           System.out.println("Finish reading file");
       }
       
        myFile.close();


Answered By - Asst. Farah
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, September 26, 2022

[FIXED] How to solve "gps" location provider requires ACCESS_FINE_LOCATION permission

 September 26, 2022     android, flutter, gps, location     No comments   

Issue

I'm working on a flutter application that use location package to track user position, It was worked fine, but by same cases I have upgrade the location package to 4.0.0 (from 3.0.1) but now a problem like appear:

E/AndroidRuntime(12224): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(12224): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) E/AndroidRuntime(12224): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980) E/AndroidRuntime(12224): Caused by: android.os.RemoteException: Remote stack trace: E/AndroidRuntime(12224): at com.android.server.LocationManagerService.checkResolutionLevelIsSufficientForProviderUseLocked(LocationManagerService.java:1979) E/AndroidRuntime(12224): at com.android.server.LocationManagerService.hasGnssPermissions(LocationManagerService.java:1752) E/AndroidRuntime(12224): at com.android.server.LocationManagerService.addGnssDataListener(LocationManagerService.java:3053) E/AndroidRuntime(12224): at com.android.server.LocationManagerService.registerGnssStatusCallback(LocationManagerService.java:2991) E/AndroidRuntime(12224): at android.location.ILocationManager$Stub.onTransact(ILocationManager.java:583)

I have correctly added the permission in android manifest file:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Also I have checked for the permission before launching the location listener but the problem is allows exist.

My LocationService:

class LocationService with ChangeNotifier {
  static LocationService _instance;

  factory LocationService() => _instance ??= LocationService._internal();
  LocationService._internal();

  bool hasPermission = false;
  bool hasService = false;
  String lastError;
  Location _locationService = Location();

  LatLng _currentLocation = LatLng(0, 0);

  set currentLocation(LatLng value) {
    _currentLocation = value;
    notifyListeners();
  }

  LatLng get currentLocation => _currentLocation;

  @override
  void dispose() {
    super.dispose();
  }

  void init() async {
    await _locationService.changeSettings(
      accuracy: LocationAccuracy.high,
      interval: 1000,
    );
    try {
      hasService = await _locationService.serviceEnabled();
      if (hasService) {
        print('Location service is enabled');

        var permission = await _locationService.requestPermission();
        hasPermission = permission == PermissionStatus.granted;

        if (hasPermission) {
          print('Location service has permission');
          final location = await _locationService.getLocation();
          currentLocation = LatLng(location.latitude, location.longitude);
          _locationService.onLocationChanged.listen((data) =>
              currentLocation = LatLng(data.latitude, data.longitude));
        } else
          throw geo.PermissionDeniedException(null);
      } else {
        hasService = await _locationService.requestService();
        if (hasService) {
          init();
          return;
        } else
          throw geo.LocationServiceDisabledException();
      }
    } catch (e) {
      lastError = e.toString();
      String message;
      if (e.runtimeType == geo.PermissionDeniedException)
        message = 'Veuillez vérifier l\'autorisation d\'activation';
      else if (e.runtimeType == geo.LocationServiceDisabledException)
        message = 'Veuillez activer votre service GPS';
      AlertUtils.showConfirmDialog(e.toString(),
          content: message, okLabel: 'Settings', okFunction: () async {
        Get.back();
        if (e.runtimeType == geo.PermissionDeniedException) {
          if (await geo.Geolocator.openAppSettings())
            AlertUtils.showConfirmDialog('Réessayez?', okLabel: 'Réessayez?',
                okFunction: () {
              Get.back();
              init();
            });
          else
            AlertUtils.showConfirmDialog(
                'Impossible d\'activer l\'autorisation automatiquement, merci de le faire manuellement.');
        } else if (e.runtimeType == geo.LocationServiceDisabledException) {
          if (await geo.Geolocator.openLocationSettings())
            AlertUtils.showConfirmDialog('Réessayez?', okLabel: 'Réessayez?',
                okFunction: () {
              Get.back();
              init();
            });
          else
            AlertUtils.showConfirmDialog(
                'Impossible d\'activer le GPS automatiquement, merci de le faire manuellement.');
        }
      });
    }
  }
}

Thanks for your help


Solution

I found that the problem is with setting to configuration of my localization pluggin before checking at the permission, soo simply I have moved it inside the if condition like:

 if (hasPermission) {
          print('Location service has permission');
          await _locationService.changeSettings(
            accuracy: LocationAccuracy.high,
            interval: 1000,
          );
          final location = await _locationService.getLocation();
          currentLocation = LatLng(location.latitude, location.longitude);
          _locationService.onLocationChanged.listen((data) =>
              currentLocation = LatLng(data.latitude, data.longitude));
        } else
          throw geo.PermissionDeniedException(null);


Answered By - Alaeddine Bouhajja
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to Get City Name by Latitude &Longitude in android?

 September 26, 2022     android, gps, location, map     No comments   

Issue

I want to city name by current location but i have latitude and longitude.how to get it? i used button click then i get double value latitude and longitude. my code in below.please help me.

Thanks!!

Button btnShowLocation;

    GPSTracker gps;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        btnShowLocation = (Button) findViewById(R.id.btnShowLocation);

        // show location button click event
        btnShowLocation.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {       
                // create class object
                gps = new GPSTracker(AndroidGPSTrackingActivity.this);

                // check if GPS enabled     
                if(gps.canGetLocation()){

                    double latitude = gps.getLatitude();
                    double longitude = gps.getLongitude();

                    // \n is for new line
                    Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();    
                }else{

                    gps.showSettingsAlert();
                }

            }
        });

I edited below code but not get cityname please help me !!!

Button btnShowLocation;

    GPSTracker gps;
    String CityName;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        btnShowLocation = (Button) findViewById(R.id.btnShowLocation);

        // show location button click event
        btnShowLocation.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // create class object
                gps = new GPSTracker(AndroidGPSTrackingActivity.this);

                // check if GPS enabled
                if (gps.canGetLocation()) {

                    double latitude = gps.getLatitude();
                    double longitude = gps.getLongitude();

                    Geocoder geocoder = new Geocoder(
                            AndroidGPSTrackingActivity.this, Locale
                                    .getDefault());
                    List<Address> addresses;
                    try {
                        Log.v("log_tag", "latitude" + latitude);
                        Log.v("log_tag", "longitude" + longitude);
                        addresses = geocoder.getFromLocation(latitude,
                                longitude, 1);
                        Log.v("log_tag", "addresses+)_+++" + addresses);
                        CityName = addresses.get(0).getAddressLine(0);
                        Log.v("log_tag", "CityName" + CityName);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    // \n is for new line
                    Toast.makeText(
                            getApplicationContext(),
                            "Your Location is - \nLat: " + latitude
                                    + "\nLong: " + longitude, Toast.LENGTH_LONG)
                            .show();
                } else {

                    gps.showSettingsAlert();
                }

            }
        });

But I get Error in below::::

03-11 17:01:46.465: W/System.err(27587): java.io.IOException: Service not Available
03-11 17:01:46.465: W/System.err(27587):    at android.location.Geocoder.getFromLocation(Geocoder.java:136)
03-11 17:01:46.465: W/System.err(27587):    at com.example.gpstracking.AndroidGPSTrackingActivity$1.onClick(AndroidGPSTrackingActivity.java:81)
03-11 17:01:46.465: W/System.err(27587):    at android.view.View.performClick(View.java:4191)
03-11 17:01:46.475: W/System.err(27587):    at android.view.View$PerformClick.run(View.java:17229)
03-11 17:01:46.475: W/System.err(27587):    at android.os.Handler.handleCallback(Handler.java:615)
03-11 17:01:46.475: W/System.err(27587):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-11 17:01:46.475: W/System.err(27587):    at android.os.Looper.loop(Looper.java:137)
03-11 17:01:46.475: W/System.err(27587):    at android.app.ActivityThread.main(ActivityThread.java:4960)
03-11 17:01:46.475: W/System.err(27587):    at java.lang.reflect.Method.invokeNative(Native Method)
03-11 17:01:46.475: W/System.err(27587):    at java.lang.reflect.Method.invoke(Method.java:511)
03-11 17:01:46.475: W/System.err(27587):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
03-11 17:01:46.475: W/System.err(27587):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
03-11 17:01:46.475: W/System.err(27587):    at dalvik.system.NativeStart.main(Native Method)
03-11 17:02:21.335: W/IInputConnectionWrapper(27587): getSelectedText on inactive InputConnection
03-11 17:02:21.335: W/IInputConnectionWrapper(27587): setComposingText on inactive InputConnection
03-11 17:02:21.425: W/IInputConnectionWrapper(27587): getExtractedText on inactive InputConnection

Solution

Use This:

 Geocoder geocoder = new Geocoder(this, Locale.getDefault());
 List<Address> addresses = geocoder.getFromLocation(MyLat, MyLong, 1);
 String cityName = addresses.get(0).getAddressLine(0);
 String stateName = addresses.get(0).getAddressLine(1);
 String countryName = addresses.get(0).getAddressLine(2);

For more in detailed google map example you check the links below: http://www.demoadda.com/demo/android/load-googlemap_107

And for the background location updates: http://www.demoadda.com/demo/android/download-android-background-location-update-service-demo_21



Answered By - Kishan Dhamat
Answer Checked By - Cary Denson (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Saturday, July 30, 2022

[FIXED] How to find the position of an Image in WPF C#?

 July 30, 2022     c#, image, location, wpf     No comments   

Issue

I have an array which stores many images within in. I am trying to figure out how to get the position of the image (x,y) within the window. I aim to put it in a timer so I can get the updated location as the program runs.

The images are added with the following code:

arrayName[p] = new Image();
arrayName[p].Source = new BitmapImage(new Uri(@"imgPlaneSprite.png", UriKind.Relative));
arrayName[p].Width = 50;
arrayName[p].Height = 50;
arrayName[p].Stretch = Stretch.Fill;

LayoutRoot.Children.Add(arrayName[p]);

Solution

try this:

arrayName[p].PointToScreen(new Point(0, 0));


Answered By - Hanebu
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, July 18, 2022

[FIXED] When do you put Javascript in body, when in head and when use doc.load?

 July 18, 2022     document-body, head, javascript, jquery, location     No comments   

Issue

Possible Duplicate:
Where to place Javascript in a HTML file?
Should I write script in the body or the head of the html?

I've always wondered, mainly because when creating pages I always run into trouble, based on the following thing:

When do you write your javascript

  • In the <head>
  • In the <body>
  • with a $(document).ready()

I could be stupid, but I've had a few times when my JavaScript (/jQuery) wasn't executed because of the wrong place or yes or no doc.ready() command. So I'm really wondering so.

Same goes for jQuery and 'var' command


Solution

$(document).ready() simply ensures that all DOM elements are loaded before your javascript is loaded.

When it doesn't matter

Without waiting for this event to fire, you may end up manipulating DOM elements or styles that are yet to exist on the page. the DOM ready event also allows you more flexibility to run scripts on different parts of the page. For example:

<div id="map"></div>
<script type="text/javascript">document.getElementById('map').style.opacity = 0;</script>

will run because the map div has been loaded before the script runs. In fact, you can get some pretty good performance improvements by placing your scripts at the bottom of the page.

When it does matter

However, if you are loading your scripts in the <head> element, most of your DOM has not loaded. This example will not work:

<script type="text/javascript">document.getElementById('map').style.opacity = 0;</script>
<div id="map"></div>

will not, since the map div has not been loaded.

A safe solution

You can avoid this by simply wait until the entire DOM has loaded:

<script type="text/javascript">$(document).ready(function () { 
    document.getElementById('map').style.opacity = 0;
});
</script>
<div id="map"></div>

There are plenty of articles that explain this, as well as the jQuery documentation itself.



Answered By - Kyle
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, May 18, 2022

[FIXED] how to insert part of image into picturebox?

 May 18, 2022     c#, image, location, partial, picturebox     No comments   

Issue

I'm not really sure if it is possible to insert a part of image into picturebox, but I would like to create an image 500*500 pixels in size and then use the parts of it as small connectable 50*50 pieces by setting the location of image inside the pictureboxes...

Is anything similar possible through use of graphics? I'm not very familiar with it... (I am talking about C# forms application...)


Solution

After some time of searching and few personal attempts I have found a solution, this isn't my own, but sadly I have forgot where did I took it from:

   private static Image cropImage(Image img, Rectangle cropArea)
   {
       Bitmap bmpImage = new Bitmap(img);
       Bitmap bmpCrop = bmpImage.Clone(cropArea,
       bmpImage.PixelFormat);
       return (Image)(bmpCrop);
   }

This will created cropped image, you can now use it in code. SAMPLE:

   Picturebox P = new Picturebox;
   P.BackgroundImage = cropImage(ImageThatWillBeCropped, new Rectangle(0,0,50,50));

If anyone finds this useful and needs explanation for rectangle, please, feel free to ask :)



Answered By - Antonio Teh Sumtin
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, May 16, 2022

[FIXED] How to change the location of `web root` folder of EasyPHP?

 May 16, 2022     easyphp, location, root     No comments   

Issue

Currently on my Windows 7 machine, it is C:\Program Files (x86)\EasyPHP-5.3.8.1\www

I want to point it into another location on drive D, says D:\code

How would I do that?


Solution

Thanks to @daviddlh 's answer, I have the simple solution for my question.

Open apache configuration file httpd.conf

Replace the default value ${path}/www by the path of our choice, says D:\code

Where does it come from? Look for DocumentRoot in apache config file (i.e. httpd.conf), we will see the below line which link us to ${path}/www

DocumentRoot "${path}/www"


Answered By - Nam G VU
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, February 4, 2022

[FIXED] How to add location to a post or a photo with facebook php sdk

 February 04, 2022     facebook, facebook-php-sdk, location, photo, php     No comments   

Issue

This is driving me nuts.

Can anyone post a practical example on this? My gratitude for life:

  1. Publish a post and add the related checkin/location info
  2. publish a photo and add the related checkin/location info.

In both cases the user delegates the action to the app. We have the access token by prior.

Please no theory, a working coding snipper ;-)

I am particularly messed up because facebook asks a nested structures of objects and arrays

Any help would be really appreciated


Solution

Grab the $user instance

$user = $facebook->getUser();

Check if the logged in user is authenticated.

if ($user) {
  try {
    // Proceed 
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

Present the login url with permissions needed for posting. Specifically the publish_streampermission as stated in the photo documentation http://developers.facebook.com/docs/reference/api/user/#photos

if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl(array(
             'scope' => 'read_stream,publish_stream,user_photos'
             ));
}

Place the me/photos call in a try/catch block to catch any exceptions that may occur.

    try {
        $facebook->setFileUploadSupport('http://yourapicallingwebsite.com/');
        $response = $facebook->api(
          '/me/photos/',
          'post',
          array(
            'message' => 'Testing the Photo Upload',
            'source' => '@/path/to/img',
            'place' => 'place_id' 
          )
        );
      }
   catch (FacebookApiException $e) {
       error_log('An error occurred posting the image');
   }

Check the response from the me/photos call

$photo_u = $facebook->api('/'.$response['id']);

Display it if your like

<img src=<?php echo $photo_u['picture'] ?>/>

Check the place name if you like

$photo_place = $photo_u['place'];
<span><?php echo $photo_place['name'] ?></span>


Answered By - phwd
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing