Turn on location services without navigating to settings page

This dialog is created by LocationSettingsRequest.Builder available in the Google Play Services. You need to add a dependency to your app build.gradle: compile ‘com.google.android.gms:play-services-location:10.0.1’ Then you can use this minimal example: private void displayLocationSettingsRequest(Context context) { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context) .addApi(LocationServices.API).build(); googleApiClient.connect(); LocationRequest locationRequest = LocationRequest.create(); locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); locationRequest.setInterval(10000); locationRequest.setFastestInterval(10000 / 2); LocationSettingsRequest.Builder builder = … Read more

Android Location Providers – GPS or Network Provider?

There are 3 location providers in Android. They are: gps –> (GPS, AGPS): Name of the GPS location provider. This provider determines location using satellites. Depending on conditions, this provider may take a while to return a location fix. Requires the permission android.permission.ACCESS_FINE_LOCATION. network –> (AGPS, CellID, WiFi MACID): Name of the network location provider. … Read more

How to mock location on device?

It seems the only way to do is to use a mock location provider. You have to enable mock locations in the development panel in your settings and add <uses-permission android:name=”android.permission.ACCESS_MOCK_LOCATION” /> to your manifest. Now you can go in your code and create your own mock location provider and set the location of this … Read more

Python + Django page redirect

It’s simple: from django.http import HttpResponseRedirect def myview(request): … return HttpResponseRedirect(“/path/”) More info in the official Django docs Update: Django 1.0 There is apparently a better way of doing this in Django now using generic views. Example – from django.views.generic.simple import redirect_to urlpatterns = patterns(”, (r’^one/$’, redirect_to, {‘url’: ‘/another/’}), #etc… ) There is more in … Read more

Nginx serves .php files as downloads, instead of executing them

Try this: Edit /etc/nginx/sites-available/default Uncomment both listen lines to make Nginx listen on port 80 IPv4 and IPv6. listen 80; ## listen for ipv4; this line is default and implied listen [::]:80 default_server ipv6only=on; ## listen for ipv6 Leave server_name alone # Make site accessible (…) server_name localhost; Add index.php to the index line root … Read more

Get User’s Current Location / Coordinates

To get a user’s current location you need to declare: let locationManager = CLLocationManager() In viewDidLoad() you have to instantiate the CLLocationManager class, like so: // Ask for Authorisation from the User. self.locationManager.requestAlwaysAuthorization() // For use in foreground self.locationManager.requestWhenInUseAuthorization() if CLLocationManager.locationServicesEnabled() { locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters locationManager.startUpdatingLocation() } Then in CLLocationManagerDelegate method you … Read more

How to get complete address from latitude and longitude?

Geocoder geocoder; List<Address> addresses; geocoder = new Geocoder(this, Locale.getDefault()); addresses = geocoder.getFromLocation(latitude, longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5 String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex() String city = addresses.get(0).getLocality(); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)