help cngcode

Title

cngcode -- Baidu Map API is widely used in China. This Stata module helps to extract longitude and latitude for a given Chinese address from Baidu Map API(http://api.map.baidu.com)

Syntax

cngcode, baidukey(string) [options]

Extracts the longitude and latitude of Chinese address from Baidu Map API

cnaddress, baidukey(string) lat(varname) long(varname) [options]

cnaddress is the inverse command for cngcode. It converts a location (pair of longitude and latitude) into the corresponding address in Chinese with Baidu Map API

Description

cngcode uses Baidu Map API v3.0 to extract longitude and latitude of Chinese address. However,
a Baidu secret key from Baidu Map API is needed upon using this command. A typical Baidu secret key
is an alphanumeric string. The option baidukey(string) is actually not optional. If you have a Baidu
key, which is, say CH8eakl6UTlEb1OakeWYvofh, the baidukey option must be specified as
baidukey(CH8eakl6UTlEb1OakeWYvofh). You can get a secret key from Baidu Map open
platform(http://lbsyun.baidu.com). The process normally will take 3-5 days after you submit your
application online. When using cngcode to map a Chinese address to a longitude and latitude location,
users can specify the address with two ways. First, combination address. With this mode, users can specify
the Chinese address with a combination of information including province, city, district and if possible,
an address. Secondly, full address, in which the user specify a full address which encompasses the
information on province and city into a single line of address. Users can also specify both, however,
if both addresses are used, cngcode will pick the one which can yield a location. If both can yield
locations, the default choice is to use the location yield from the combination address. But users can
change this priority with ffirst option, which will return the location from the full address if the
location of full address and combination address are different.

cnaddress uses Baidu Map API to extract Chinese address of the location defined by longitude
and latitude. Again, users need to get a secret key from Baidu Map open platform, and input it with
the baidukey() option. You will get province, city, district, street, full address and a sematic
description of the location defined by longitude and latitude.

Both cngcode and cnaddress require Stata version 14 or higher.

Options for cngcode

Credentials(required)

baidukey(string) is required before using this command. You can get a secret key from Baidumap open platform(http://lbsyun.baidu.com). The process normally will take 3-5 days after you submit your application online.

Address

province(varname) specifies the string variable that contains the name of province.

city(varname) specifies the string variable that contains the name of city.

district(varname) specifies the string variable that contains the name of district.

address(varname) specifies the string variable that contains the address.

fulladdress(varname) specifies the string variable that contains the full address.

Response switches

latitude(newvar) is required when you want to specify the name of the variable that contains latitude. Default choice is longitude.

longitude(newvar) is required when you want to specify the name of the variable that contains longitude. Default choice is latitude.

coordtype(string) is required when you want to specify the type of coordinate responsed:

gcj02ll indicates that you will get GCJ-02 longitude and latitude.

bd09ll indicates that you will get BD-90 longitude and latitude.

bd09mc indicates that you will get the BD-90 metric coordinates.

ffirst If the location yield from the combination address is different from the return location from the full address, ffirst specifies that the location from the full location is a first priority.

Options for cnaddress

Credentials(required)

baidukey(string) is required before you use this command. You can get a secret key from Baidumap open platform(http://lbsyun.baidu.com). The process normally will take 3-5 days after you submit your application online.

Location(required)

latitude(varname) specifies the numeric variable that contains latitude.

longitude(varname) specifies the numeric variable that contains longitude.

Response switches

country(newvar) is required when you want to specify the name of the variable that contains the name of country.

province(newvar) is required when you want to specify the name of the variable that contains the name of province.

city(newvar) is required when you want to specify the name of the variable that contains the name of city.

district(newvar) is required when you want to specify the name of the variable that contains the name of district.

street(newvar) is required when you want to specify the name of the variable that contains the name of street.

address(newvar) is required when you want to specify the name of the variable that contains the full address.

description(newvar) is required when you want to specify the name of the variable that contains the sematic description of the location from Baidu Map.

coordtype(string) is required when you want to specify the type of coordinate you submit:

wgs84ll indicates that you submit the WGS-80 longitude and latitude.

gcj02ll indicates that you submit the GCJ-02 longitude and latitude.

bd09ll indicates that you submit the BD-09 longtitude and latitude, which is also the default choice.

bd09mc indicates that you submit the BD-09 metric coordinates.

Example

Input the address

`"clear"'

`"input str15 prov str15 city str15 dist str60 addr str100 fulladdress"'

`""湖北省" "武汉市" "" "南湖大道中南财经政法大学" """'

`""" "北京市" "海淀区" "北京大学" "湖北省武汉市南湖大道中南财经政法大学""'

`""" "" "" "" "北京市海淀区北京大学""'

`"end"'

extracts longitude and latitude of the combination of province, city, district and address

`"cngcode, baidukey(your secret key) province(prov) city(city) district(dist) address(addr)"'

`"list prov - addr longitude latitude"'

extracts longitude and latitude of fulladdress

`"cngcode, baidukey(your secret key) fulladdress(fulladdress) lat(lat1) long(long1)"'

`"list fulladdress long1 lat1"'

When you specify both province/city/district/address and fulladdress,
you will first get longitude and latitude from the combination of province,
city, district, address. Afterwards for those observations that can not
extract longitude and latitude, you will get them from full address mode.

`"cngcode, baidukey(your secret key) province(prov) city(city) district(dist) address(addr) fulladdress(fulladdress) lat(lat2) long(long2)"'

`"list prov - fulladdress long2 lat2"'

`"cngcode, baidukey(your secret key) province(prov) city(city) district(dist) address(addr) fulladdress(fulladdress) lat(lat3) long(long3) ffirst"'

`"list prov - fulladdress long3 lat3"'

extract Chinese address of location defined by longitude and latitude

`"keep long3 lat3"'

`"cnaddress, baidukey(your secret key) lat(lat3) long(long3)"'

`"list"'

Author

Chuntao LI

China Stata Club(爬虫俱乐部)

Wuhan, China

chtl@zuel.edu.cn

Yuan XUE

China Stata Club(爬虫俱乐部)

Wuhan, China

xueyuan19920310@163.com