Gmap上标记用户的当前位置

Gmap上标记用户的当前位置

本文介绍了如何在Primefaces Gmap上标记用户的当前位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Gmap中,我们可以通过传递自定义的纬度和经度来标记所需的位置.有什么方法可以添加标记来映射用户的当前位置?有没有一种方法可以获取用户的纬度和经度?有人做过吗?请分享您的想法?

In Gmap we can mark, desired location by passing custom latitude and longitude.Is there any way to add marker to map for user's CURRENT LOCATION.?Is there a way to get user's latitude and longitude?Has any one done it before?Please share your idea?

推荐答案

您需要确定用户的IP地址,然后将其提供给某些IP地理位置工具/API,以获取经度/纬度的地理位置.最后,将此信息用于您的Google Map.

You need to figure the user's IP address and then feed it to some IP geo location tool/API in order to get the geo location in latitude/longitude. Finally use this information for your Google Map.

JSF可以为您做的就是为您提供用户的IP地址,如下所示:

All JSF can do for you is giving you the user's IP address as follows:

ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
String ip = request.getRemoteAddr();
// ...

如果您还要考虑代理,请检查X-Forwarded-For标头:

If you'd like to take proxies into account as well, then check X-Forwarded-For header:

ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
String ip = request.getRemoteAddr();
String forwardedFor = request.getHeader("X-Forwarded-For");

if (forwardedFor != null) {
    ip = forwardedFor.split("\\s*,\\s*", 2)[0];
}

// ...

您又需要使用哪个IP地理位置工具/API,您必须自己回答一个问题.只需向Google提供关键字" ip地理位置"即可.

Which IP geo location tool/API you in turn have to use is a question which you've to answer yourself. Just feed the keywords "ip geo location" to Google to get started.

这篇关于如何在Primefaces Gmap上标记用户的当前位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 07:11