Developers can not turn the GPS on or off using code Blocks on Android version above about 4.1. Even developers using Android Studio can not turn the GPS hardware on/off. The GPS hardware must be turned on and off manually. Use the device's Location Settings (or the device's notification/settings bar)
You can use an ActivityStarter to provide the users with the location settings screen https://groups.google.com/forum/#!msg/mitappinventortest/aFpGSCdAN5A/Eo5FtBhODAAJ
. The User can use that screen to manually change the GPS settings. App Inventor 2 developers can turn on/off the LocationSensor using the set LocationSensor.Enabled to true or false but that merely disables your app from reporting what the GPS receiver reports if it is on.
Is that what you wanted to know?