def layer_url_template(layer, conf): if layer not in known_layers: oa = openanything.fetch( 'http://maps.google.com/maps?t=' + map_server_query[layer]) if oa['status'] != 200: print "Trying to fetch http://maps.google.com/maps but failed" return None html = oa['data'] known_layers[layer] = parse_start_page(layer, html, conf) return known_layers[layer]
def layer_url_template(layer, conf): if layer not in known_layers: oa = openanything.fetch('http://maps.google.com/maps?t=' + map_server_query[layer]) if oa['status'] != 200: print "Trying to fetch http://maps.google.com/maps but failed" return None html = oa['data'] known_layers[layer] = parse_start_page(layer, html, conf) return known_layers[layer]
def parse_page(): gwmNum = '1170' oa = openanything.fetch('http://www.google.com/mapmaker') if oa['status'] != 200: print "Trying to fetch Google Map Maker but failed" else: html = oa['data'] p = re.compile('gwm.([0-9]+)') m = p.search(html) if m: gwmNum = m.group(1) return gwmNum
def layer_url_template(layer, conf): if layer not in known_layers: map_server_query = {"gmap":"m", "ghyb":"h", "gsat":"k", "gter":"p"} oa = openanything.fetch( 'http://maps.google.com/maps?t=' + map_server_query[MAP_SERVICES[layer]["TextID"]]) if oa['status'] != 200: print "Trying to fetch http://maps.google.com/maps but failed" return None html = oa['data'] known_layers[layer] = parse_start_page(layer, html, conf) return known_layers[layer]
def layer_url_template(layer, conf): if layer not in known_layers: map_server_query = {"gmap": "m", "ghyb": "h", "gsat": "k", "gter": "p"} oa = openanything.fetch( 'http://maps.google.com/maps?t=' + map_server_query[MAP_SERVICES[layer]["TextID"]]) if oa['status'] != 200: print "Trying to fetch http://maps.google.com/maps but failed" return None html = oa['data'] known_layers[layer] = parse_start_page(layer, html, conf) return known_layers[layer]
def search_location(location, key='AIzaSyB3d6ZZvE0msnWbh9gX3bAN0bSFf4m8DuE'): print 'downloading the following location:', location try: oa = openanything.fetch('https://maps.googleapis.com/maps/api/geocode/json?key=%s&address=' % key + urllib.quote_plus(location), agent="Mozilla/5.0") except Exception: return 'error=Can not connect to http://maps.googleapis.com', None if oa['status'] != 200: return 'error=Can not connect to http://maps.googleapis.com', None try: data = json.loads(oa['data'])["results"][0] geo = data["geometry"]["location"] location = data["formatted_address"] return location, (float(geo['lat']), float(geo['lng']), 8) except Exception: return 'error=Location %s not found' % location, None
def search_location(location): print 'downloading the following location:', location try: oa = openanything.fetch('http://maps.google.com/maps?q=' + urllib.quote_plus(location), agent="Mozilla/5.0") except Exception: return 'error=Can not connect to http://maps.google.com', None if oa['status'] != 200: return 'error=Can not connect to http://maps.google.com', None match = 0 html = oa['data'] if html.find('We could not understand the location') < 0 and \ html.find('Did you mean:') < 0: encpa = 'charset[ ]?= ?([^ ]+)"' p = re.compile(encpa, re.IGNORECASE) match = p.search(html) if match: encoding = match.group(1) else: encoding = "ASCII" # List of patterns to look for the location name paList = [ "laddr:'([^']+)'", "daddr:'([^']+)'", 'laddr:"([^"]+)"', 'daddr:"([^"]+)"' ] for srtPattern in paList: p = re.compile(srtPattern) match = p.search(html) if match: break if match: location = match.group(1) else: return 'error=Location %s not found' % location, None # List of patterns to look for the latitude & longitude paList = [ 'var zoom = (?P<zoom>[0-9]+);.*insertTiles.*,(?P<lat>[0-9.-]+),(?P<lng>[0-9.-]+),zoom', 'center:{lat:(?P<lat>[0-9.-]+),lng:(?P<lng>[0-9.-]+)}.*zoom:(?P<zoom>[0-9.-]+)', 'markers:.*lat:(?P<lat>[0-9.-]+),lng:(?P<lng>[0-9.-]+).*laddr:', 'dtlsUrl:.*x26sll=(?P<lat>[0-9.-]+),(?P<lng>[0-9.-]+).*x26sspn', ] for srtPattern in paList: p = re.compile(srtPattern) match = p.search(html) if match: break if match: zoom = 10 try: zoom = set_zoom(MAP_MAX_ZOOM_LEVEL - int(match.group('zoom'))) except IndexError: p = re.compile('center:.*zoom:([0-9.-]+).*mapType:') m2 = p.search(html) if m2: zoom = set_zoom(MAP_MAX_ZOOM_LEVEL - int(m2.group(1))) location = unicode(location, encoding, errors='ignore') if encoding.upper() == "ISO-8859-1": location = _fix_iso_8859_1_issues(location) return location, (float(match.group('lat')), float(match.group('lng')), int(zoom)) else: return 'error=Unable to get latitude and longitude of %s ' % location
def search_location(location): print 'downloading the following location:', location try: oa = openanything.fetch('http://maps.google.com/maps?q=' + urllib.quote_plus(location), agent="Mozilla/5.0") except Exception: return 'error=Can not connect to http://maps.google.com', None if oa['status'] != 200: return 'error=Can not connect to http://maps.google.com', None match = 0 html = oa['data'] if html.find('We could not understand the location') < 0 and \ html.find('Did you mean:') < 0: encpa = 'charset[ ]?= ?([^ ]+)"' p = re.compile(encpa, re.IGNORECASE) match = p.search(html) if match: encoding = match.group(1) else: encoding = "ASCII" # List of patterns to look for the location name paList = ["laddr:'([^']+)'", "daddr:'([^']+)'", 'laddr:"([^"]+)"', 'daddr:"([^"]+)"'] for srtPattern in paList: p = re.compile(srtPattern) match = p.search(html) if match: break if match: location = match.group(1) else: return 'error=Location %s not found' % location, None # List of patterns to look for the latitude & longitude paList = [ 'var zoom = (?P<zoom>[0-9]+);.*insertTiles.*,(?P<lat>[0-9.-]+),(?P<lng>[0-9.-]+),zoom', 'center:{lat:(?P<lat>[0-9.-]+),lng:(?P<lng>[0-9.-]+)}.*zoom:(?P<zoom>[0-9.-]+)', 'markers:.*lat:(?P<lat>[0-9.-]+),lng:(?P<lng>[0-9.-]+).*laddr:', 'dtlsUrl:.*x26sll=(?P<lat>[0-9.-]+),(?P<lng>[0-9.-]+).*x26sspn', ] for srtPattern in paList: p = re.compile(srtPattern) match = p.search(html) if match: break if match: zoom = 10 try: zoom = set_zoom(MAP_MAX_ZOOM_LEVEL - int(match.group('zoom'))) except IndexError: p = re.compile('center:.*zoom:([0-9.-]+).*mapType:') m2 = p.search(html) if m2: zoom = set_zoom(MAP_MAX_ZOOM_LEVEL - int(m2.group(1))) location = unicode(location, encoding, errors='ignore') if encoding.upper() == "ISO-8859-1": location = _fix_iso_8859_1_issues(location) return location, (float(match.group('lat')), float(match.group('lng')), int(zoom)) else: return 'error=Unable to get latitude and longitude of %s ' % location