如何使用PHP来抓取这些内容,并且只获取lat/long
How to use PHP to scrape this content and only get the lat/long
比方说,我有这个代码:
var i = new GIcon(G_DEFAULT_ICON);
var latlng = new GLatLng(33.013489, -117.140167);
map.setCenter(latlng, 9);
map.panTo(latlng);
var i = new GIcon(G_DEFAULT_ICON);
var latlng = new GLatLng(32.979286, -117.02623);
map.setCenter(latlng, 9);
map.panTo(latlng);
var i = new GIcon(G_DEFAULT_ICON);
var latlng = new GLatLng(32.746319, -117.141449);
map.setCenter(latlng, 9);
map.panTo(latlng);
var i = new GIcon(G_DEFAULT_ICON);
var latlng = new GLatLng(32.758286, -117.125053);
map.setCenter(latlng, 9);
map.panTo(latlng);
如何使用PHP返回列表或仅返回纬度和经度。所以GLatLng()
之间的任何东西
所以我最终会得到一个数组,看起来像这样:
32.758286, -117.125053
32.979286, -117.02623
32.746319, -117.141449
32.758286, -117.125053
preg_match_all('~
(?<='() (?# starts with opening parentheses )
(?P<lat>['d.-]+) (?# then a digit, dot or dash more than one time )
's*,'s* (?# followed by a comma with any number of spaces around )
(?P<lng>['d.-]+) (?# then another digit, dot or dash more than one time )
(?=')) (?# ends with closing parentheses )
~x', $str, $matches);
var_dump($matches);
您可以先找到命名为GLatLng(
的开始字符串,然后找到结束字符串)
,并取两者之间的值。只要你能找到起始字符串,就重复。
演示:
$result = [];
$start = 'GLatLng(';
$offset = 0;
while (false !== $pos = strpos($buffer, $start, $offset))
{
$offset = $pos + strlen($start);
$result[] = substr($buffer, $offset, strpos($buffer, ')', $offset) - $offset);
}
类似这样的东西:
/* Split the raw input by its newline characters */
$input = explode("'r'n", $rawInput);
$outputStack = array();
foreach ($input as $inputRow)
{
splitRow = explode("new GLatLng(", $inputRow);
if (sizeof(splitRow) > 1)
{
/* if you can split the row into more than one peice, you know what's going to be in splitRow[1]: your lat, long */
array_push($output_stack, str_replace(");", "", splitRow[1]));
}
}
相关文章:
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- jquery试图按名称获取按钮位置
- 如何在jQuery中获取元素的形式
- 如何在php文件中获取$.post-ajax传递的值
- 在Shopify中获取博客文章的图片
- 使用Javascript获取所选选项ID
- 在jQuery中获取表的行索引
- 获取给定lat-long的javascript中的当前日期和时间
- 从GeoJson文件中获取单独的Lat和Lng值
- 仅在JS中从LAT-LONG获取大陆
- 本地存储上的传单标记,如何获取标记 lat lng 并从存储中排除
- MapBox 方向 - 获取自己的 Lat 和 Lng 方向
- GoogleMaps和GeoIP:从IP获取Lat、Long并绘制地图
- 如何使用PHP来抓取这些内容,并且只获取lat/long
- 从一个有谷歌地图的地方获取lat和lng
- 从lat和long获取邮政编码
- 如何使用c#.net从数据库中获取lat-long
- 使用传单控制搜索获取并显示来自地址的lat-long
- 从JavaScript中获取一个lat/long对,用于PHP中的date_sunset
- Leaflet.Geosearch:从地址获取lon/lat