def get_geolocation(): # get Geolocation (lat,lng) from google from geolocation.google_maps import GoogleMaps google_maps = GoogleMaps(api_key='AIzaSyBEQ64NGaq3p_kXC7DuCj55FZdLhpPCMO8') location = google_maps.search(location=LOCATION) my_location = location.first() return my_location
def coordinates(address): coord=[] google_maps=GoogleMaps(api_key=key) location=google_maps.search(location=address) my_location=location.first() coord.append(my_location.lat) coord.append(my_location.lng) return coord
def coordinates(address): coord = [] google_maps = GoogleMaps(api_key=key) location = google_maps.search(location=address) my_location = location.first() coord.append(my_location.lat) coord.append(my_location.lng) return coord
def setLocation(request): if request.method == "GET": return render(request, "shopping_location.html") elif request.method == "POST": google_maps = GoogleMaps(api_key='AIzaSyC8hihi26xJqO77v4R2qJMii0cn6S2eW8w') location = google_maps.search(location=request.POST['address']) my = location.first() u = User.objects.get(username=request.session['user']) PickupLocation(user=u, address="%s %s %s %s" % (my.street_number, my.route, my.city, my.postal_code)).save() return HttpResponseRedirect("/shopping/profile")
def make_postalcode(postalcode_string): """ Takes in zipcode as a string, gets lat and long info using the GoogleMaps API, and adds the zipcode to the PostalCodes table. """ google_maps = GoogleMaps(api_key=os.environ["GOOGLE_API_KEY"]) location = google_maps.search(location=postalcode_string).first() print "\n\n\n\n Google Maps API: location is %r \n\n" % location a = PostalCode(postalcode=int(postalcode_string), latitude=location.lat, longitude=location.lng) db.session.add(a) db.session.commit() temp = PostalCode.query.get(int(postalcode_string)) print "****************\n\n\n\n\n MADE POSTALCODE %r\n\n\n\n\n*************" % temp
def main(): print ("hello world") currentTime = [] address = '1280 Main street, Hamilton ON' google_maps = GoogleMaps(api_key='AIzaSyAb649ImqHvCeKtAA6YdT3Q6WbRRH2FrrQ') location = google_maps.search(location=address) my_location = location.first() locationdata = (str(my_location.lat) + ',' + str(my_location.lng)) timedata = datetime.datetime.now() current = str(timedata) currentTime. append(current[17:19]) currentTime. append(current[14:16]) currentTime. append(current[11:13]) currentTime. append(current[8:10]) currentTime. append(current[5:7]) currentTime. append(current[2:4]) print(locationdata) print currentTime[0] + ',' + currentTime[1] + ',' + currentTime[2] + ',' + currentTime[3] + ',' + currentTime[4] + ',' + currentTime[5]
def main(): print("hello world") currentTime = [] address = '1280 Main street, Hamilton ON' google_maps = GoogleMaps(api_key='AIzaSyAb649ImqHvCeKtAA6YdT3Q6WbRRH2FrrQ') location = google_maps.search(location=address) my_location = location.first() locationdata = (str(my_location.lat) + ',' + str(my_location.lng)) timedata = datetime.datetime.now() current = str(timedata) currentTime.append(current[17:19]) currentTime.append(current[14:16]) currentTime.append(current[11:13]) currentTime.append(current[8:10]) currentTime.append(current[5:7]) currentTime.append(current[2:4]) print(locationdata) print currentTime[0] + ',' + currentTime[1] + ',' + currentTime[ 2] + ',' + currentTime[3] + ',' + currentTime[4] + ',' + currentTime[5]
from geolocation.google_maps import GoogleMaps from geolocation.distance_matrix import const address = "98 w 4th st dunkirk ny 14048" #origins = ["501 Woodrow Avenue Dunkirk New York 14048"] #destinations = ['36 Center street Fredonia New York 14063'] google_maps = GoogleMaps(api_key='AIzaSyBDrUT23Cl31dLl-T6ZRPERYefp8-nH7bY') #items = google_maps.distance(origins, destinations).all() # default mode parameter is const.MODE_DRIVING. location = google_maps.search(location=address) # sends search to Google Maps. print(location.all()) # returns all locations. my_location = location.first() # returns only first location. print(my_location.city) print(my_location.route) print(my_location.street_number) print(my_location.postal_code) for administrative_area in my_location.administrative_area: print("{}: {}".format(administrative_area.area_type, administrative_area.name)) print(my_location.country) print(my_location.country_shortcut) print(my_location.formatted_address) print(my_location.lat) print(my_location.lng) # reverse geocode
from geolocation.google_maps import GoogleMaps import IP2Location import geoip2.database # Enter GoogleMap API Key google_maps = GoogleMaps(api_key='AIzaSyDJvXt5YtoHbMkQFBQk-Nok5SgdLwpF5R4') #Define Address for Lookup address = "New York City Wall Street 12" location = google_maps.search(location=address) # sends search to Google Maps. my_location = location.first() # returns only first location. # Read GeoLite Database for IP Address Lookup reader = geoip2.database.Reader('GeoLite2-City.mmdb') #Enter IP Address for Lookup response = reader.city('208.30.113.22') #Print IP Address information print("====================") print(response.city.name) print(response.postal.code) print(response.location.latitude) print(str(response.location.longitude) + " \n") #Google Maps IP Coordinate look up print("My Location - Lat " + str(my_location.lat)) print("My Location - Long " + str(my_location.lng)) # reverse geocode lat = 40.7060008
# -*- coding: utf-8 -*- from geolocation.google_maps import GoogleMaps if __name__ == "__main__": address = "New York City" google_maps = GoogleMaps(api_key='your_google_maps_key') location = google_maps.search(location=address) print location.all() my_location = location.first() print my_location.city print my_location.route print my_location.street_number print my_location.postal_code for administrative_area in my_location.administrative_area: print "%s: %s" % (administrative_area.area_type, administrative_area.name) print my_location.country print my_location.country_shortcut print my_location.formatted_address print my_location.lat print my_location.lng
class GeolocationTest(unittest.TestCase): def setUp(self): self.google_maps = GoogleMaps(api_key=TEST_API_KEY) def test_query(self): address = "New York City Wall Street 12" location = self.google_maps.search(address) self.assertIsNotNone(location.all()) def test_city(self): address = "New York City Wall Street 12" location = self.google_maps.search(address) my_location = location.first() self.assertEqual('New York', my_location.city.decode('utf-8')) def test_route(self): address = "New York City Wall Street 12" location = self.google_maps.search(address) my_location = location.first() self.assertEqual('Wall Street', my_location.route.decode('utf-8')) def test_country(self): address = "New York City Wall Street 12" location = self.google_maps.search(address) my_location = location.first() self.assertEqual('United States', my_location.country.decode('utf-8')) def test_country_shortcut(self): address = "New York City Wall Street 12" location = self.google_maps.search(address) my_location = location.first() self.assertEqual('US', my_location.country_shortcut.decode('utf-8')) def test_lat(self): address = "New York City Wall Street 12" location = self.google_maps.search(address) my_location = location.first() self.assertEqual(40.7060008, my_location.lat) def test_lng(self): address = "New York City Wall Street 12" location = self.google_maps.search(address) my_location = location.first() self.assertEqual(-74.0088189, my_location.lng) def test_formatted_address(self): address = "New York City Wall Street 12" location = self.google_maps.search(address) my_location = location.first() self.assertEqual('Wall Street, New York, NY, USA', my_location.formatted_address) def test_administrative_area_level_1(self): address = "New York City Wall Street 12" location = self.google_maps.search(address) my_location = location.first() self.assertEqual( 'New York', my_location.administrative_area[0].name.decode('utf-8')) def test_administrative_area_level_2(self): address = "New York City Wall Street 12" location = self.google_maps.search(address) my_location = location.first() self.assertEqual( 'New York County', my_location.administrative_area[1].name.decode('utf-8')) def test_coding(self): address = "São Paulo" my_location = self.google_maps.search(address).first() self.assertEqual(u"São Paulo", my_location.city.decode('utf-8')) def test_latlng(self): lat = 37.42291810 lng = -122.08542120 my_location = self.google_maps.search(lat=lat, lng=lng).first() self.assertEqual('Mountain View', my_location.city.decode('utf-8'))
class GeolocationTest(unittest.TestCase): def setUp(self): self.google_maps = GoogleMaps(api_key=TEST_API_KEY) def test_query(self): address = "New York City Wall Street 15" location = self.google_maps.search(address) self.assertIsNotNone(location.all()) def test_city(self): address = "New York City Wall Street 14" location = self.google_maps.search(address) my_location = location.first() self.assertEqual('New York', my_location.city.decode('utf-8')) def test_route(self): address = "New York City Wall Street 12" location = self.google_maps.search(address) my_location = location.first() self.assertEqual('Wall Street', my_location.route.decode('utf-8')) def test_country(self): address = "New York City Wall Street 110" location = self.google_maps.search(address) my_location = location.first() self.assertEqual('United States', my_location.country.decode('utf-8')) def test_country_shortcut(self): address = "New York City Wall Street 2" location = self.google_maps.search(address) my_location = location.first() self.assertEqual('US', my_location.country_shortcut.decode('utf-8')) def test_lat(self): address = "New York City Wall Street 1" location = self.google_maps.search(address) my_location = location.first() self.assertAlmostEqual(40.7060081, my_location.lat, 2) def test_lng(self): address = "New York City Wall Street 19" location = self.google_maps.search(address) my_location = location.first() self.assertAlmostEqual(-74.0134436, my_location.lng, 2) def test_formatted_address(self): address = "New York City Wall Street 124" location = self.google_maps.search(address) my_location = location.first() self.assertEqual('Charging Bull, Broadway, New York, NY 10004, USA', my_location.formatted_address) def test_administrative_area_level_1(self): address = "New York City Wall Street 125" location = self.google_maps.search(address) my_location = location.first() self.assertEqual( 'New York', my_location.administrative_area[0].name.decode('utf-8')) def test_administrative_area_level_2(self): address = "New York City Wall Street 126" location = self.google_maps.search(address) my_location = location.first() self.assertEqual( 'New York County', my_location.administrative_area[1].name.decode('utf-8')) def test_coding(self): address = "São Paulo" my_location = self.google_maps.search(address).first() self.assertEqual(u"São Paulo", my_location.city.decode('utf-8')) def test_latlng(self): lat = 37.4229210 lng = -122.0852112 my_location = self.google_maps.search(lat=lat, lng=lng).first() self.assertEqual('Mountain View', my_location.city.decode('utf-8')) def test_administrative_area_resets(self): address = "São Paulo" sao_paulo = self.google_maps.search(address).first() address = "Houston, TX" houston = self.google_maps.search(address).first() self.assertNotEqual(sao_paulo, houston)
<h2> Enter Postcode </h2> <form method="post" action="webapi.py"> <p>command: <input type="text" name="command"/></p> </form> """ form = cgi.FieldStorage() Userpc = form["command"].value if command != "" : print "<p> Finding Data For Postcode" + Userpc + "</p>" pcr = pc.get(Userpc) pcr2 = pcr["geo"] UserLat = pcr2["lat"] UserLong = pcr2["lng"] location = g_m.search(location=Userpc) #locate = location.first() #print locate.city print location from police_api import PoliceAPI papi = PoliceAPI() locate = papi.locate_neighbourhood(UserLat, UserLong) print "Police Data for" + Userpc #print "<h2>" + locate + "</h2>" print "<h2> Force </h2<" print "<h2> Contact details </h2> " print print "<h3>" + locate.force + "</h3>" print "<h3>" + papi.get.crimes.area + "</h3>" #OSM = OsmApi() #print " "
with open(sCsvOut, 'w') as fOut: oWriter = csv.writer(fOut) oWriter.writerow(["subnum", "address_lat_i", "address_lng_i"]) with open(sCsvIn, 'r') as fIn: oReader = csv.reader(fIn) next(fIn) #skip heading for lRow in oReader: i+= 1 sSubnum = lRow[0] sAddress = lRow[1] print "{0}:\t{1} \t{2}".format(i, sSubnum, sAddress) if sAddress != "": oLocation = oGoogleMaps.search(location=sAddress) # sends search to Google Maps. try: oFirstLocation = oLocation.first() # returns only first location. sLat = oFirstLocation.lat sLng = oFirstLocation.lng except AttributeError: #if no hits sLat = "" sLng = "" else: sLat = "" sLng = "" oWriter.writerow([sSubnum, sLat, sLng])
# -*- coding: utf-8 -*- from geolocation.google_maps import GoogleMaps if __name__ == "__main__": address = "New York City" google_maps = GoogleMaps(api_key='your_google_maps_key') lat = 40.7060008 lng = -74.0088189 location = google_maps.search(lat=lat, lng=lng) print location.all() my_location = location.first() print my_location.city print my_location.route print my_location.street_number print my_location.postal_code for administrative_area in my_location.administrative_area: print "%s: %s" % (administrative_area.area_type, administrative_area.name) print my_location.country print my_location.country_shortcut print my_location.formatted_address print my_location.lat
import csv from geolocation.google_maps import GoogleMaps data_dir="/home/sachin/Data/EPFL/Sem 2/DH/newdata/" google_maps = GoogleMaps(api_key=YOUR_KEY) with open(data_dir+"locations.csv","r") as fin: with open(data_dir+"coordinates.csv","w") as fout: reader = csv.reader(fin) writer=csv.writer(fout) for line in reader: location = google_maps.search(location=line[1]).first() # sends search to Google Maps. line.append(location.lat) line.append(location.lng) writer.writerow(line)
class GeolocationTest(unittest.TestCase): def setUp(self): self.google_maps = GoogleMaps(api_key=TEST_API_KEY) def test_query(self): address = "New York City Wall Street 15" location = self.google_maps.search(address) self.assertIsNotNone(location.all()) def test_city(self): address = "New York City Wall Street 14" location = self.google_maps.search(address) my_location = location.first() self.assertEqual('New York', my_location.city.decode('utf-8')) def test_route(self): address = "New York City Wall Street 12" location = self.google_maps.search(address) my_location = location.first() self.assertEqual('Wall Street', my_location.route.decode('utf-8')) def test_country(self): address = "New York City Wall Street 110" location = self.google_maps.search(address) my_location = location.first() self.assertEqual('United States', my_location.country.decode('utf-8')) def test_country_shortcut(self): address = "New York City Wall Street 2" location = self.google_maps.search(address) my_location = location.first() self.assertEqual('US', my_location.country_shortcut.decode('utf-8')) def test_lat(self): address = "New York City Wall Street 1" location = self.google_maps.search(address) my_location = location.first() self.assertEqual(40.7060081, my_location.lat) def test_lng(self): address = "New York City Wall Street 19" location = self.google_maps.search(address) my_location = location.first() self.assertEqual(-74.0134436, my_location.lng) def test_formatted_address(self): address = "New York City Wall Street 124" location = self.google_maps.search(address) my_location = location.first() self.assertEqual('Charging Bull, Broadway, New York, NY 10004, USA', my_location.formatted_address) def test_administrative_area_level_1(self): address = "New York City Wall Street 125" location = self.google_maps.search(address) my_location = location.first() self.assertEqual( 'New York', my_location.administrative_area[0].name.decode('utf-8')) def test_administrative_area_level_2(self): address = "New York City Wall Street 126" location = self.google_maps.search(address) my_location = location.first() self.assertEqual( 'New York County', my_location.administrative_area[1].name.decode('utf-8')) def test_coding(self): address = "São Paulo" my_location = self.google_maps.search(address).first() self.assertEqual(u"São Paulo", my_location.city.decode('utf-8')) def test_latlng(self): lat = 37.4229210 lng = -122.0852112 my_location = self.google_maps.search(lat=lat, lng=lng).first() self.assertEqual('Mountain View', my_location.city.decode('utf-8'))
with open(sCsvOut, 'w') as fOut: oWriter = csv.writer(fOut) oWriter.writerow(["subnum", "address_lat_i", "address_lng_i"]) with open(sCsvIn, 'r') as fIn: oReader = csv.reader(fIn) next(fIn) #skip heading for lRow in oReader: i += 1 sSubnum = lRow[0] sAddress = lRow[1] print "{0}:\t{1} \t{2}".format(i, sSubnum, sAddress) if sAddress != "": oLocation = oGoogleMaps.search( location=sAddress) # sends search to Google Maps. try: oFirstLocation = oLocation.first( ) # returns only first location. sLat = oFirstLocation.lat sLng = oFirstLocation.lng except AttributeError: #if no hits sLat = "" sLng = "" else: sLat = "" sLng = ""
from geolocation.google_maps import GoogleMaps google_maps = GoogleMaps(api_key='AIzaSyBXW--FnarS7Ype4a0WZPTV-JVpHpIwPHA') f = open('E:/city.txt', 'a+') for line in open('e:\\project\\Data\\000\\Trajectory\\a.plt'): lat = line.split()[0] lng = line.split()[1] my_location = google_maps.search(lat=lat, lng=lng).first() print(my_location.city) print(my_location.route) print(my_location.street_number) print(my_location.postal_code) f.write(my_location.city + ' ') f.write(str(my_location.route) + ' ') f.write(my_location.postal_code + '\n') f.write(my_location.street_number + ' \n') f.close() #lat = 39.984333 #lng = 116.318417 #print lat #print lng
address = "818 West 46th St, Minneapolis MN" # sample user input #address = "55123" #address = "610 Opperman Dr, Eagan, MN" #address = '1455 Upper 55th St E, Inver Grove Heights, MN 55077' apiKey='ffd1c56f9abcf84872116b4cc2dfcf31' # api key for walk/transit score walkscore = WalkScore(apiKey) #transitscore = TransitScore(apiKey) ### extract location information #### geolocator = Nominatim() location = geolocator.geocode(address) #print(location.raw) google_maps = GoogleMaps(api_key='AIzaSyAP3JK8NPEfz8OTdYCGNgpv6wYCUsx4gf8') google_location = google_maps.search(location=address) #print(google_location.all()) # returns all locations. my_location = google_location.first() # returns only first location. code_city = {} code_score = {} with open(metro_tran, 'rU') as infile: for index, line in enumerate(infile): if index == 0: continue content = line.rstrip('\n').split(',') #print(content) primary_city = content[0] score = float(content[1])
# -*- coding: utf-8 -*- from geolocation.google_maps import GoogleMaps if __name__ == "__main__": address = "New York City" google_maps = GoogleMaps(api_key='your_google_maps_key') lat = 40.7060008 lng = -74.0088189 location = google_maps.search(lat=lat, lng=lng) print location.all() my_location = location.first() print my_location.city print my_location.route print my_location.street_number print my_location.postal_code for administrative_area in my_location.administrative_area: print "%s: %s" % (administrative_area.area_type, administrative_area.name) print my_location.country print my_location.country_shortcut print my_location.formatted_address