search
Homephp教程php手册微信获取用户地理位置信息的原理与步骤,获取地理位置

微信获取用户地理位置信息的原理与步骤,获取地理位置

在微信公众服务号开发需求中经常有获取用户位置信息的功能,通过用户的位置信息,可以做一些地图导航,以及基于LBS的营销活动。

下面通过给大家介绍微信服务号获取用户位置信息的原理与步骤。

原理

1. 位置信息获取流程

2. 位置信息报文

<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>

参数说明:

参数 描述
ToUserName 开发者微信号
FromUserName 发送方帐号(一个OpenID)
CreateTime 消息创建时间 (整型)
MsgType 消息类型,event
Event 事件类型,LOCATION
Latitude 地理位置纬度
Longitude 地理位置经度
Precision 地理位置精度


获取位置信息步骤

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"].

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

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)