Flutter: how to get location coordinates of point in the center of screen

4,122

You can do it by using ScreenCoordinate:

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
double screenWidth = MediaQuery.of(context).size.width *
       MediaQuery.of(context).devicePixelRatio;
double screenHeight = MediaQuery.of(context).size.height *
       MediaQuery.of(context).devicePixelRatio;

double middleX = screenWidth / 2;
double middleY = screenHeight / 2;

ScreenCoordinate screenCoordinate = ScreenCoordinate(x: middleX.round(), y: middleY.round());

LatLng middlePoint = await googleMapController.getLatLng(screenCoordinate);
Share:
4,122
Karrar
Author by

Karrar

MEFN stack developer / F stands for Flutter 😁

Updated on December 16, 2022

Comments

  • Karrar
    Karrar over 1 year

    I'm using google maps in my flutter app, I want to put a pointer in the middle of the screen so it will be easy for the users to choose the location the look for by just moving the map and making the pointer in the middle of the screen points to the location they look for

    so how then can I get the coordinates that sits in the middle of the screen ,exactly the same where the pointer is