Home > Backend Development > PHP Tutorial > The principles and steps for WeChat to obtain user geographical location information, obtain geographical location_PHP tutorial

The principles and steps for WeChat to obtain user geographical location information, obtain geographical location_PHP tutorial

WBOY
Release: 2016-07-12 09:04:59
Original
2004 people have browsed it

The principles and steps for WeChat to obtain user geographical location information. Obtaining geographical location

In the development requirements of WeChat public service accounts, there is often a function to obtain user location information, through the user's location Information, you can do some map navigation and LBS-based marketing activities.

The following will introduce to you the principles and steps for obtaining user location information through WeChat service accounts.

Principle

1. Location information acquisition process

2. Location information message

<xml><ToUserName><![CDATA[gh_public_member_account]]></ToUserName>
<FromUserName><![CDATA[oNEGGwGfl8f5xMEqVHToL63LDL40]]></FromUserName>
<CreateTime>1444035882</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[LOCATION]]></Event>
<Latitude>28.701618</Latitude>
<Longitude>115.818817</Longitude>
<Precision>30.000000</Precision>
</xml>
Copy after login

Parameter description:

参数 描述
ToUserName 开发者WeChat ID
FromUserName Sender account (an OpenID)
CreateTime Message creation time (integer)
MsgType Message type, event
Event Event type, LOCATION
Latitude Geographical location latitude
Longitude Geographical location longitude
Precision Geolocation Accuracy


获取位置信息步骤

1. 申请服务号认证

只有通过认证的服务号,才能够获取访问微信高级服务的权限。

2. 开启用户位置信息获取功能

开发者中心 -> 获取用户地理位置

3. weiPHP地理位置信息消息处理。

1. 配置微信服务号开发接口

微信服务器将会把用户与微信之间的交互事件消息,通过此接口推送给SP服务器。

2. 在WeixinController的IndexAction中处理location消息。

将xml消息转化为php数组,然后取出经纬度信息,以备使用。

$content = file_get_contents ( 'php://input' );
$data = new \SimpleXMLElement ( $content );
foreach ( $data as $key => $value ) {
 $this->data [$key] = strval ( $value );
}
// to use data["longitude"]; data["latitude"].
Copy after login

以上通过图文的方式给大家展示了微信获取用户地理位置信息的原理与步骤,希望大家喜欢。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1071234.htmlTechArticle微信获取用户地理位置信息的原理与步骤,获取地理位置 在微信公众服务号开发需求中经常有获取用户位置信息的功能,通过用户的位置信...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template