PowerDNS already has a module for this. (http://www.debiantutorials.com/install-configure-powerdns-geo-backend-cdngeographic-dns-blancing/)
There is also another project that does this on a bigger scale, http://gdnsd.org/. A talk about about gDNSd, https://www.youtube.com/watch?v=WF75IGx9svM.