当前位置: 首页>>代码示例>>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;未经允许,请勿转载。