I want to to retrieve the Latitude and Longitude values in the following string with Regex
. Please help me do this.
<script type="text/javascript">
function initialize() {
var mapOptions = {
zoom: 18,
center: new google.maps.LatLng(0.6213000841833666, 73.46202224493027)
};
}
</script>
Here's what I have tried so far.
var data = await Client.GetResponse(URL);
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(data);
var script = doc.DocumentNode.Descendants()
.Where(x => x.Name == "script").FirstOrDefault();
if (script != null) {
Match match = Regex.Match(script.InnerText, @"LatLng([A-Za-z0-9\-]+),$", RegexOptions.IgnoreCase);
if (match.Success) {
// blah blah
}
}
Match m = Regex.Match(xml, @"LatLng\(([\d\.]+)\,\s*([\d\.]+)\)");
if(m.Success)
{
Trace.WriteLine(string.Format("Lat:{0} - Lng:{1}", m.Groups[1].Value, m.Groups[2].Value));
}
may be this helpful for you
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication11
{
class Program
{
static void Main(string[] args)
{
var strings = @"<script type='text/javascript'>
function initialize() {
var mapOptions = {
zoom: 18,
center: new google.maps.LatLng(0.6213000841833666, 73.46202224493027)
};
}
</script>";
var group = Regex.Match(strings,"maps.LatLng\\((?<lat>.*?),\\s*(?<long>.*?)\\)",RegexOptions.IgnoreCase).Groups;
var lat = group["lat"].Value;
var lon = group["long"].Value;
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.