It's a broad topic, from where do you need to start. If you have GPS coordinates you do standard GIS queries. Then there are IP2Geo services that are widespread in the industry but those have questionable accuracy and don't work at all with cellular connections.
If you want to know how advertising work then look at the OpenRTB specification. The majority use this to communicate user information to the rest of adtech. Google has their own but also support OpenRTB if you want the inefficiency of JSON.