當前位置: 首頁>>代碼示例>>Python>>正文


Python geocoders.GoogleV3方法代碼示例

本文整理匯總了Python中geopy.geocoders.GoogleV3方法的典型用法代碼示例。如果您正苦於以下問題:Python geocoders.GoogleV3方法的具體用法?Python geocoders.GoogleV3怎麽用?Python geocoders.GoogleV3使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在geopy.geocoders的用法示例。


在下文中一共展示了geocoders.GoogleV3方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_pos_by_name

# 需要導入模塊: from geopy import geocoders [as 別名]
# 或者: from geopy.geocoders import GoogleV3 [as 別名]
def get_pos_by_name(self, location_name):
        # Check if given location name, belongs to favorite_locations
        favorite_location_coords = self._get_pos_by_fav_location(location_name)

        if favorite_location_coords is not None:
            return favorite_location_coords

        # Check if the given location is already a coordinate.
        if ',' in location_name:
            possible_coordinates = re.findall(
                "[-]?\d{1,3}(?:[.]\d+)?", location_name
            )
            if len(possible_coordinates) >= 2:
                # 2 matches, this must be a coordinate. We'll bypass the Google
                # geocode so we keep the exact location.
                self.logger.info(
                    '[x] Coordinates found in passed in location, '
                    'not geocoding.'
                )
                return float(possible_coordinates[0]), float(possible_coordinates[1]), (float(possible_coordinates[2]) if len(possible_coordinates) == 3 else self.alt)

        geolocator = GoogleV3(api_key=self.config.gmapkey)
        loc = geolocator.geocode(location_name, timeout=10)

        return float(loc.latitude), float(loc.longitude), float(loc.altitude) 
開發者ID:PokemonGoF,項目名稱:PokemonGo-Bot,代碼行數:27,代碼來源:__init__.py

示例2: set_location

# 需要導入模塊: from geopy import geocoders [as 別名]
# 或者: from geopy.geocoders import GoogleV3 [as 別名]
def set_location(location_name):
    geolocator = GoogleV3()
    prog = re.compile('^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$')
    global origin_lat
    global origin_lon
    if prog.match(location_name):
        local_lat, local_lng = [float(x) for x in location_name.split(",")]
        alt = 0
        origin_lat, origin_lon = local_lat, local_lng
    else:
        loc = geolocator.geocode(location_name)
        origin_lat, origin_lon = local_lat, local_lng = loc.latitude, loc.longitude
        alt = loc.altitude
        print '[!] Your given location: {}'.format(loc.address.encode('utf-8'))

    print('[!] lat/long/alt: {} {} {}'.format(local_lat, local_lng, alt))
    set_location_coords(local_lat, local_lng, alt) 
開發者ID:rubenmak,項目名稱:PokemonGo-SlackBot,代碼行數:19,代碼來源:example.py

示例3: get_pos_by_name

# 需要導入模塊: from geopy import geocoders [as 別名]
# 或者: from geopy.geocoders import GoogleV3 [as 別名]
def get_pos_by_name(self, location_name):
        # Check if given location name, belongs to favorite_locations
        favorite_location_coords = self._get_pos_by_fav_location(location_name)

        if favorite_location_coords is not None:
            return favorite_location_coords

        # Check if the given location is already a coordinate.
        if ',' in location_name:
            possible_coordinates = re.findall(
                "[-]?\d{1,3}[.]\d{3,7}", location_name
            )
            if len(possible_coordinates) >= 2:
                # 2 matches, this must be a coordinate. We'll bypass the Google
                # geocode so we keep the exact location.
                self.logger.info(
                    '[x] Coordinates found in passed in location, '
                    'not geocoding.'
                )
                return float(possible_coordinates[0]), float(possible_coordinates[1]), (float(possible_coordinates[2]) if len(possible_coordinates) == 3 else self.alt)

        geolocator = GoogleV3(api_key=self.config.gmapkey)
        loc = geolocator.geocode(location_name, timeout=10)

        return float(loc.latitude), float(loc.longitude), float(loc.altitude) 
開發者ID:PokemonGoF,項目名稱:PokemonGo-Bot-Backup,代碼行數:27,代碼來源:__init__.py

示例4: query_google

# 需要導入模塊: from geopy import geocoders [as 別名]
# 或者: from geopy.geocoders import GoogleV3 [as 別名]
def query_google(latitude, longitude):
        coordinates = "%s, %s" % (latitude, longitude)
        Logger.log_more_verbose(
            "Querying Google Geocoder for: %s" % coordinates)
        try:
            g = geocoders.GoogleV3()
            r = g.reverse(coordinates)
            if r:
                return r[0][0].encode("UTF-8")
        except Exception, e:
            fmt = traceback.format_exc()
            Logger.log_error_verbose("Error: %s" % str(e))
            Logger.log_error_more_verbose(fmt)


    #-------------------------------------------------------------------------- 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:18,代碼來源:geoip.py

示例5: __init__

# 需要導入模塊: from geopy import geocoders [as 別名]
# 或者: from geopy.geocoders import GoogleV3 [as 別名]
def __init__(self):
        self.geocoder = GoogleV3()
        self.updated_tweets = [] 
開發者ID:romaintha,項目名稱:twitter,代碼行數:5,代碼來源:geocoding.py

示例6: geocode_location

# 需要導入模塊: from geopy import geocoders [as 別名]
# 或者: from geopy.geocoders import GoogleV3 [as 別名]
def geocode_location(location):
    """Geocode a location string using Google geocoder."""
    geocoder = geocoders.GoogleV3()
    try:
        result = geocoder.geocode(location, exactly_one=False)
    except Exception:
        return None, None
    try:
        ctr_lat, ctr_lng = result[0][1]
    except IndexError:
        return None, None

    return clean_coords(coords=(ctr_lat, ctr_lng)) 
開發者ID:ofa,項目名稱:connect,代碼行數:15,代碼來源:location.py

示例7: get_pos_by_name

# 需要導入模塊: from geopy import geocoders [as 別名]
# 或者: from geopy.geocoders import GoogleV3 [as 別名]
def get_pos_by_name(location_name):
    geolocator = GoogleV3()
    loc = geolocator.geocode(location_name, timeout=10)
    if not loc:
        return None

    log.info("Location for '%s' found: %s", location_name, loc.address)
    log.info('Coordinates (lat/long/alt) for location: %s %s %s', loc.latitude, loc.longitude, loc.altitude)

    return (loc.latitude, loc.longitude, loc.altitude) 
開發者ID:favll,項目名稱:pogom,代碼行數:12,代碼來源:utilities.py

示例8: get_pos_by_name

# 需要導入模塊: from geopy import geocoders [as 別名]
# 或者: from geopy.geocoders import GoogleV3 [as 別名]
def get_pos_by_name(location_name):
    geolocator = GoogleV3()
    loc = geolocator.geocode(location_name, timeout=10)

    logger.debug('location: %s', loc.address.encode('utf-8'))
    logger.debug('lat, long, alt: %s, %s, %s', loc.latitude, loc.longitude, loc.altitude)

    return (loc.latitude, loc.longitude, loc.altitude), loc.address.encode('utf-8') 
開發者ID:timwah,項目名稱:pokeslack,代碼行數:10,代碼來源:pokeutil.py

示例9: login

# 需要導入模塊: from geopy import geocoders [as 別名]
# 或者: from geopy.geocoders import GoogleV3 [as 別名]
def login(self, provider, username, password):
        # login needs base class "create_request"
        self.useVanillaRequest = True
        
        # Get Timecode and Country Code
        country_code = "US"
        timezone = "America/Chicago"
        geolocator = GoogleV3(api_key=self.config.gmapkey)
        
        if self.config.locale_by_location:
            try:
                location = geolocator.reverse((self.actual_lat, self.actual_lng), timeout = 10, exactly_one=True)
                country_code = self.get_component(location,'country')
            except:
                self.logger.warning("Please make sure you have google api key and enable Google Maps Geocoding API at console.developers.google.com")
            
            try:    
                timezone = geolocator.timezone([self.actual_lat, self.actual_lng], timeout=10)
            except:
                self.logger.warning("Please make sure you have google api key and enable Google Maps Time Zone API at console.developers.google.com")

        # Start login process
        try:
            if self.config.proxy:
                PGoApi.set_authentication(
                    self,
                    provider,
                    username=username,
                    password=password,
                    proxy_config={'http': self.config.proxy, 'https': self.config.proxy}
                )
            else:
                PGoApi.set_authentication(
                    self,
                    provider,
                    username=username,
                    password=password
                )
        except:
            raise
        try:
            if self.config.locale_by_location:
                response = PGoApi.app_simulation_login(self,country_code,timezone.zone)
            else:
                response = PGoApi.app_simulation_login(self) # To prevent user who have not update the api being caught off guard by errors
        except BadHashRequestException:
            self.logger.warning("Your hashkey seems to have expired or is not accepted!")
            self.logger.warning("Please set a valid hash key in your auth JSON file!")
            exit(-3)
            raise
        except BannedAccountException:
            self.logger.warning("This account is banned!")
            exit(-3)
            raise
        except:
            raise
        # cleanup code
        self.useVanillaRequest = False
        return response 
開發者ID:PokemonGoF,項目名稱:PokemonGo-Bot,代碼行數:61,代碼來源:api_wrapper.py

示例10: geocode

# 需要導入模塊: from geopy import geocoders [as 別名]
# 或者: from geopy.geocoders import GoogleV3 [as 別名]
def geocode(self, resource):
        """
        Performs geocoding on the provided resource and updates its formatted
        address, latitude, and longitude.

        Args:
            resource: A resource from which the address components will be
                retrieved and used to update its formatted address,
                latitude, and longitude.

        Raises:
            geopy.exc.GeopyError: An error occurred attempting to access the
                geocoder.
        """

        # Make sure we generated something meaningful
        if resource.address is not None and not resource.address.isspace():
            # Now query the geocoder with this formatted string
            geolocator = GoogleV3(api_key=self.api_key)

            new_location = geolocator.geocode(
                resource.address,
                exactly_one=True)

            if new_location is not None:
                new_res_location = ''

                if new_location.address and \
                        not new_location.address.isspace():
                    resource.address = new_location.address

                if new_location.latitude is not None and \
                        new_location.longitude is not None:
                    resource.latitude = new_location.latitude
                    resource.longitude = new_location.longitude

                # Look at the raw response for address components
                if new_location.raw:
                    address_components = new_location.raw.get(
                        'address_components')

                    if address_components:
                        # Get the city/county/state strings
                        city_str, county_str, state_str = \
                            self.get_locality_strings(address_components)

                        # Now build the location based on those strings,
                        # preferring city to county
                        new_res_location = city_str or county_str or ''

                        if state_str:
                            # Add a comma and space between the city/county
                            # and state
                            if new_res_location:
                                new_res_location = new_res_location + ', '

                            new_res_location = new_res_location + state_str

                # After all of that, update the location
                resource.location = new_res_location
        pass 
開發者ID:radremedy,項目名稱:radremedy,代碼行數:63,代碼來源:geocoder.py


注:本文中的geopy.geocoders.GoogleV3方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。