← All articles

GPS with Google Maps

Abdallah hossam · 2026-11-06 · 6 min read

GPS with Google Maps

The history of GPS (Global Positioning System) is a fascinating journey through technology and innovation, evolving over decades to become a vital tool for navigation, mapping, and timing across the globe. Here’s a detailed overview:

Early Development

  • 1920s: The concept of radio navigation began with the development of radio waves for locating ships at sea. The U.S. Navy experimented with radio signals to determine positions.
  • 1940s: During World War II, the U.S. military developed more sophisticated navigation systems, including LORAN (Long Range Navigation), which used radio signals from land-based stations to determine a receiver’s position.

Birth of Satellite Navigation

  • 1950s: The Soviet Union launched the first artificial satellite, Sputnik, in 1957. This event marked the beginning of the space age and sparked interest in satellite-based navigation.
  • 1960s: The U.S. Department of Defense initiated the TRANSIT program, which used satellites for navigation. This system allowed submarines to determine their position using satellite signals, but it was primarily designed for military use.

Development of GPS

  • 1973: The U.S. Department of Defense formally began developing GPS as a military navigation system, aiming to create a global positioning system that could provide accurate and reliable location data.
  • 1978: The first GPS satellite, Navstar 1, was launched. This satellite was part of the initial constellation of satellites designed to provide global coverage.
  • 1983: Following the downing of Korean Air Flight 007, President Ronald Reagan announced that GPS would be made available for civilian use.

Expansion and Improvements

  • 1993: The GPS system was fully operational, consisting of 24 satellites in orbit. The system provided accurate positioning data worldwide, benefiting both military and civilian applications.
  • 1995: The U.S. government declared GPS fully operational, with enhanced accuracy due to improvements in satellite technology and the introduction of new signals.

Civilian Applications

  • 2000: The U.S. government discontinued selective availability, which had intentionally degraded civilian GPS accuracy. This change allowed civilian users to access the full accuracy of GPS, typically within 5 to 10 meters.
  • 2000s: GPS technology began to be widely adopted in various industries, including automotive navigation, aviation, maritime navigation, and outdoor recreation. The technology also started to be integrated into smartphones, making GPS accessible to the general public.

Modern Era and Global Navigation Satellite Systems (GNSS)

  • 2010s: Other countries developed their own GNSS systems, including Russia’s GLONASS, the European Union’s Galileo, and China’s BeiDou. These systems increased global coverage and redundancy.
  • 2018: The U.S. Air Force declared the GPS III satellite system operational, offering improved accuracy and resilience against jamming and interference.

.2020: GPS technology continues to evolve, with ongoing improvements in satellite technology, signal processing, and integration with other technologies (like inertial navigation systems) to enhance accuracy and reliability. The rise of location-based services, autonomous vehicles, and the Internet of Things (IoT) has further expanded the use of GPS.

To use Google Maps in a Flutter application, you’ll need to follow a few steps for setup and implementation. Here’s a guide to help you get started:

1. Set Up Your Project in Google Cloud Console

  1. Go to the Google Cloud Console.
  2. Create a new project or select an existing one.
  3. Enable the Maps SDK for Android and the Maps SDK for iOS in the APIs & Services section.
  4. Generate an API Key from Credentials.

2. Add the Google Maps Flutter Package

Add the google_maps_flutter package in your pubspec.yaml file:

dependencies:
google_maps_flutter: latest_version

Then, install the dependencies by running:

flutter pub get

3. Configure API Keys for Android and iOS

Android Configuration

  1. Open android/app/src/main/AndroidManifest.xml.
  2. Inside the <application> tag, add the following meta-data tag with your API key:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY" />

iOS Configuration

  1. In your ios/Runner directory, open AppDelegate.swift (or AppDelegate.m for Objective-C).
  2. Import the GoogleMaps library and initialize it with your API key:
import GoogleMaps

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GMSServices.provideAPIKey("YOUR_API_KEY")
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}

4. Implement Google Maps in Flutter

After setup, you can create a Google Maps widget in your Flutter app. Here’s a basic example:

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Google Maps Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MapScreen(),
);
}
}

class MapScreen extends StatefulWidget {
@override
_MapScreenState createState() => _MapScreenState();
}

class _MapScreenState extends State<MapScreen> {
late GoogleMapController _mapController;

// Define the initial camera position (e.g., San Francisco)
final CameraPosition _initialPosition = CameraPosition(
target: LatLng(37.7749, -122.4194),
zoom: 10.0,
);

// Define a set of markers
final Set<Marker> _markers = {
Marker(
markerId: MarkerId('san_francisco'),
position: LatLng(37.7749, -122.4194),
infoWindow: InfoWindow(
title: 'San Francisco',
snippet: 'An interesting city',
),
icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueRed),
),
};

// Map created callback
void _onMapCreated(GoogleMapController controller) {
_mapController = controller;
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Google Maps in Flutter'),
),
body: GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: _initialPosition,
markers: _markers,
mapType: MapType.normal,
myLocationEnabled: true,
zoomControlsEnabled: true,
),
floatingActionButton: FloatingActionButton(
onPressed: () {
// Move camera to a new position (example: Los Angeles)
_mapController.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(
target: LatLng(34.0522, -118.2437), // Los Angeles coordinates
zoom: 10.0,
),
),
);
},
child: Icon(Icons.location_pin),
),
);
}
}

But What if you want to get the user location ?!

To use Google Maps with the Geolocator package in Flutter, you’ll need to set up both google_maps_flutter and geolocator packages. This will enable showing the user’s current location on the map and updating the location as they move.

1. Add Dependencies

Add google_maps_flutter and geolocator in your pubspec.yaml:

dependencies:
flutter:
sdk: flutter
google_maps_flutter: latest_version
geolocator: latest_version
geocoding: latest_version # Optional, if you want to convert coordinates to addresses

Run:

flutter pub get

2. Configure Permissions for Location Access

Android

In android/app/src/main/AndroidManifest.xml, add the following permissions outside the <application> tag:

<manifest>
<!-- Required for geolocation -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>

iOS

In ios/Runner/Info.plist, add the following keys:

<key>NSLocationWhenInUseUsageDescription</key>
<string>We need your location to show it on the map.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>We need your location to show it on the map.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Location is used to display your current location on the map.</string>

3. Full Code Example with Google Maps and Geolocator

Here is the complete Flutter code to set up a map with the user’s current location:

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:geolocator/geolocator.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Google Maps with Geolocator',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MapScreen(),
);
}
}

class MapScreen extends StatefulWidget {
@override
_MapScreenState createState() => _MapScreenState();
}

class _MapScreenState extends State<MapScreen> {
late GoogleMapController _mapController;
Position? _currentPosition;
final Set<Marker> _markers = {};

// Initial Camera Position - if user location not available
static const CameraPosition _initialPosition = CameraPosition(
target: LatLng(37.7749, -122.4194), // San Francisco as default location
zoom: 10.0,
);

@override
void initState() {
super.initState();
_getCurrentLocation();
}

// Method to get the current location of the user
Future<void> _getCurrentLocation() async {
bool serviceEnabled;
LocationPermission permission;

// Check if location services are enabled
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
await Geolocator.openLocationSettings();
return;
}

// Check for location permissions
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
return;
}
}
if (permission == LocationPermission.deniedForever) {
return;
}

// Get the current location
Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);

setState(() {
_currentPosition = position;
_markers.add(
Marker(
markerId: MarkerId('currentLocation'),
position: LatLng(position.latitude, position.longitude),
infoWindow: InfoWindow(
title: 'Your Location',
),
icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueBlue),
),
);
});

// Move the camera to the current location
_mapController.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(
target: LatLng(position.latitude, position.longitude),
zoom: 14.0,
),
),
);
}

// Callback when the map is created
void _onMapCreated(GoogleMapController controller) {
_mapController = controller;
if (_currentPosition != null) {
_mapController.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(
target: LatLng(_currentPosition!.latitude, _currentPosition!.longitude),
zoom: 14.0,
),
),
);
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Google Maps with Geolocator'),
),
body: GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: _initialPosition,
markers: _markers,
myLocationEnabled: true,
myLocationButtonEnabled: true,
),
floatingActionButton: FloatingActionButton(
onPressed: _getCurrentLocation,
child: Icon(Icons.location_searching),
),
);
}
}

google-maps · gps · flutter · gps-navigation · gps-tracking-system

Originally published on Medium

Share on LinkedIn