1:根据百度官方文档配置后台
2:c++代码
a:LexLocation.hpp
#pragma once
#include <string>
#include <functional>
namespace Lex
{
void InitLocation();
bool GetCity(std::function<void(std::string)> OnLocationResult);
}
b:LexLocation.cpp
#include "LexLocation.hpp"
#include "cocos2d.h"
#include "platform/android/jni/JniHelper.h"
static std::function<void(std::string)> OnLocationResult;
namespace Lex
{
void OnResult(std::string city)
{
if (OnLocationResult) OnLocationResult(city);
OnLocationResult = nullptr;
}
extern "C" {
void Java_lexlib_bdLocate_BDLocateCall_Result(JNIEnv *env, jobject obj, jstring jresult)
{
std::string result = env->GetStringUTFChars(jresult, nullptr);
CCLOG("11111111111111111111111111111111111%s", result.data());
OnResult(result);
}
}
bool Locate()
{
cocos2d::JniMethodInfo payM;
bool isHave = cocos2d::JniHelper::getStaticMethodInfo(payM, "lexlib/bdLocate/BDLocateCall", "StartLocate",
"()V");
bool resulte = false;
if (isHave)
{
payM.env->CallStaticVoidMethod(payM.classID, payM.methodID);
}